Silence a few remaining -Wconversion warnings.

This commit is contained in:
Todd C. Miller
2023-08-23 14:56:50 -06:00
parent 522ac12f21
commit df969d30b4
3 changed files with 21 additions and 20 deletions

View File

@@ -200,7 +200,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags)
}
}
nready = sudo_ev_poll(base->pfds, base->pfd_high + 1, timeout);
nready = sudo_ev_poll(base->pfds, (nfds_t)base->pfd_high + 1, timeout);
switch (nready) {
case -1:
/* Error: EINTR (signal) or EINVAL (nfds > RLIMIT_NOFILE) */

View File

@@ -249,9 +249,9 @@ start:
}
for (i = 0; i < len; ) {
size_t wanted = len - i;
ssize_t ret = read(fd, (char *)buf + i, wanted);
size_t ret = (size_t)read(fd, (char *)buf + i, wanted);
if (ret == -1) {
if (ret == (size_t)-1) {
if (errno == EAGAIN || errno == EINTR)
continue;
close(fd);
@@ -343,7 +343,7 @@ static int
getentropy_getrandom(void *buf, size_t len)
{
int pre_errno = errno;
int ret;
long ret;
/*
* Try descriptor-less getrandom(), in non-blocking mode.
@@ -415,9 +415,9 @@ getentropy_fallback(void *buf, size_t len)
unsigned char *results = NULL;
int save_errno = errno, e, faster = 0;
int ret = -1;
static int cnt;
static size_t cnt;
unsigned int repeat;
long pgs;
size_t pgs;
struct timespec ts;
struct timeval tv;
struct rusage ru;
@@ -431,7 +431,8 @@ getentropy_fallback(void *buf, size_t len)
if (len == 0)
return 0;
if ((pgs = sysconf(_SC_PAGESIZE)) == -1)
pgs = (size_t)sysconf(_SC_PAGESIZE);
if (pgs == (size_t)-1)
return -1;
if ((ctx = sudo_digest_alloc(SUDO_DIGEST_SHA512)) == NULL)
return -1;
@@ -454,8 +455,8 @@ getentropy_fallback(void *buf, size_t len)
for (j = 0; j < repeat; j++) {
HX((e = gettimeofday(&tv, NULL)) == -1, tv);
if (e != -1) {
cnt += (int)tv.tv_sec;
cnt += (int)tv.tv_usec;
cnt += (size_t)tv.tv_sec;
cnt += (size_t)tv.tv_usec;
}
#ifdef HAVE_DL_ITERATE_PHDR
dl_iterate_phdr(getentropy_phdr, ctx);
@@ -525,8 +526,7 @@ getentropy_fallback(void *buf, size_t len)
mo = cnt %
(mm[m].npg * pgs - 1);
p[mo] = 1;
cnt += (int)((long)(mm[m].p)
/ pgs);
cnt += (size_t)mm[m].p / pgs;
}
#ifdef HAVE_CLOCK_GETTIME
@@ -536,15 +536,15 @@ getentropy_fallback(void *buf, size_t len)
HX((e = clock_gettime(cl[ii],
&ts)) == -1, ts);
if (e != -1)
cnt += (int)ts.tv_nsec;
cnt += (size_t)ts.tv_nsec;
}
#endif /* HAVE_CLOCK_GETTIME */
HX((e = getrusage(RUSAGE_SELF,
&ru)) == -1, ru);
if (e != -1) {
cnt += (int)ru.ru_utime.tv_sec;
cnt += (int)ru.ru_utime.tv_usec;
cnt += (size_t)ru.ru_utime.tv_sec;
cnt += (size_t)ru.ru_utime.tv_usec;
}
}
@@ -592,8 +592,8 @@ getentropy_fallback(void *buf, size_t len)
HX((e = getrusage(RUSAGE_CHILDREN,
&ru)) == -1, ru);
if (e != -1) {
cnt += (int)ru.ru_utime.tv_sec;
cnt += (int)ru.ru_utime.tv_usec;
cnt += (size_t)ru.ru_utime.tv_sec;
cnt += (size_t)ru.ru_utime.tv_usec;
}
} else {
/* Subsequent hashes absorb previous result */
@@ -602,8 +602,8 @@ getentropy_fallback(void *buf, size_t len)
HX((e = gettimeofday(&tv, NULL)) == -1, tv);
if (e != -1) {
cnt += (int)tv.tv_sec;
cnt += (int)tv.tv_usec;
cnt += (size_t)tv.tv_sec;
cnt += (size_t)tv.tv_usec;
}
HD(cnt);

View File

@@ -1347,7 +1347,7 @@ sudo_ldap_sasl_interact(LDAP *ld, unsigned int flags, void *_auth_id,
else
interact->result = "";
interact->len = strlen(interact->result);
interact->len = (unsigned int)strlen(interact->result);
#if SASL_VERSION_MAJOR < 2
interact->result = strdup(interact->result);
if (interact->result == NULL) {
@@ -1778,7 +1778,8 @@ sudo_ldap_result_add_entry(struct ldap_result *lres, LDAPMessage *entry)
* of 100 entries to save on allocation time.
*/
if (++lres->nentries > lres->allocated_entries) {
size_t allocated_entries = lres->allocated_entries + ALLOCATION_INCREMENT;
unsigned int allocated_entries =
lres->allocated_entries + ALLOCATION_INCREMENT;
struct ldap_entry_wrapper *entries = reallocarray(lres->entries,
allocated_entries, sizeof(lres->entries[0]));
if (entries == NULL)