Avoid compiler casting warnings by assigning to the same type where possible

This saves instructions that are related to casting as well as compiler warnings.
This commit is contained in:
Rose
2023-05-18 14:38:18 -04:00
parent a0b074cc9c
commit e54ba33ea0
50 changed files with 175 additions and 168 deletions

View File

@@ -98,7 +98,7 @@ sudo_ev_activate_sigevents(struct sudo_event_base *base)
{
struct sudo_event *ev;
sigset_t set, oset;
int i;
unsigned int i;
debug_decl(sudo_ev_activate_sigevents, SUDO_DEBUG_EVENT);
/*
@@ -168,7 +168,7 @@ signal_pipe_cb(int fd, int what, void *v)
static int
sudo_ev_base_init(struct sudo_event_base *base)
{
int i;
unsigned int i;
debug_decl(sudo_ev_base_init, SUDO_DEBUG_EVENT);
TAILQ_INIT(&base->events);
@@ -218,7 +218,7 @@ void
sudo_ev_base_free_v1(struct sudo_event_base *base)
{
struct sudo_event *ev, *next;
int i;
unsigned int i;
debug_decl(sudo_ev_base_free, SUDO_DEBUG_EVENT);
if (base == NULL)

View File

@@ -70,7 +70,7 @@ sudo_explicit_bzero(void *v, size_t n)
/* Updating through a volatile pointer should not be optimized away. */
while (n--)
*s++ = '\0';
*s++ = 0;
}
# endif /* HAVE_BZERO */

View File

@@ -72,7 +72,7 @@ do_cleanup(void)
}
}
void
sudo_noreturn void
sudo_fatal_nodebug_v1(const char *fmt, ...)
{
va_list ap;
@@ -84,7 +84,7 @@ sudo_fatal_nodebug_v1(const char *fmt, ...)
exit(EXIT_FAILURE);
}
void
sudo_noreturn void
sudo_fatalx_nodebug_v1(const char *fmt, ...)
{
va_list ap;
@@ -96,7 +96,7 @@ sudo_fatalx_nodebug_v1(const char *fmt, ...)
exit(EXIT_FAILURE);
}
void
sudo_noreturn void
sudo_vfatal_nodebug_v1(const char *fmt, va_list ap)
{
warning(strerror(errno), fmt, ap);
@@ -104,7 +104,7 @@ sudo_vfatal_nodebug_v1(const char *fmt, va_list ap)
exit(EXIT_FAILURE);
}
void
sudo_noreturn void
sudo_vfatalx_nodebug_v1(const char *fmt, va_list ap)
{
warning(NULL, fmt, ap);
@@ -143,7 +143,7 @@ sudo_vwarnx_nodebug_v1(const char *fmt, va_list ap)
warning(NULL, fmt, ap);
}
void
sudo_noreturn void
sudo_gai_fatal_nodebug_v1(int errnum, const char *fmt, ...)
{
va_list ap;
@@ -155,7 +155,7 @@ sudo_gai_fatal_nodebug_v1(int errnum, const char *fmt, ...)
exit(EXIT_FAILURE);
}
void
sudo_noreturn void
sudo_gai_vfatal_nodebug_v1(int errnum, const char *fmt, va_list ap)
{
warning(gai_strerror(errnum), fmt, ap);

View File

@@ -282,7 +282,7 @@ gai_lookup(const char *nodename, int flags, int socktype, unsigned short port,
struct in_addr addr;
struct hostent *host;
const char *canonical;
int i;
size_t i;
if (inet_pton(AF_INET, nodename, &addr)) {
canonical = (flags & AI_CANONNAME) ? nodename : NULL;

View File

@@ -413,9 +413,11 @@ static int
getentropy_fallback(void *buf, size_t len)
{
unsigned char *results = NULL;
int save_errno = errno, e, pgs = sysconf(_SC_PAGESIZE), faster = 0, repeat;
int save_errno = errno, e, faster = 0;
int ret = -1;
static int cnt;
unsigned int repeat;
long pgs;
struct timespec ts;
struct timeval tv;
struct rusage ru;
@@ -427,8 +429,12 @@ getentropy_fallback(void *buf, size_t len)
size_t i, ii, m, digest_len;
char *p;
if (len == 0)
return 0;
if ((pgs = sysconf(_SC_PAGESIZE)) == -1)
return -1;
if ((ctx = sudo_digest_alloc(SUDO_DIGEST_SHA512)) == NULL)
goto done;
return -1;
digest_len = sudo_digest_getlen(SUDO_DIGEST_SHA512);
if (digest_len == (size_t)-1 || (results = malloc(digest_len)) == NULL)
goto done;
@@ -442,8 +448,9 @@ getentropy_fallback(void *buf, size_t len)
lastpid = pid;
repeat = REPEAT;
}
for (i = 0; i < len; ) {
int j;
i = 0;
do {
unsigned int j;
for (j = 0; j < repeat; j++) {
HX((e = gettimeofday(&tv, NULL)) == -1, tv);
if (e != -1) {
@@ -625,7 +632,7 @@ getentropy_fallback(void *buf, size_t len)
sudo_digest_reset(ctx);
memcpy((char *)buf + i, results, min(digest_len, len - i));
i += min(digest_len, len - i);
}
} while (i < len);
if (gotdata(buf, len) == 0) {
errno = save_errno;
ret = 0; /* satisfied */

View File

@@ -35,7 +35,7 @@ int
sudo_hexchar_v1(const char *s)
{
unsigned char result[2];
int i;
unsigned int i;
debug_decl(sudo_hexchar, SUDO_DEBUG_UTIL);
for (i = 0; i < 2; i++) {

View File

@@ -76,7 +76,7 @@ inet_ntop4(const unsigned char *src, char *dst, socklen_t size)
int len;
len = snprintf(dst, size, fmt, src[0], src[1], src[2], src[3]);
if (len < 0 || (size_t)len >= size) {
if (len < 0 || (socklen_t)len >= size) {
errno = ENOSPC;
return (NULL);
}
@@ -113,7 +113,7 @@ inet_ntop6(const unsigned char *src, char *dst, socklen_t size)
*/
memset(words, 0, sizeof(words));
for (i = 0; i < NS_IN6ADDRSZ; i++)
words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
words[i / 2] |= (src[i] << ((1 - (i & 1)) << 3));
best.base = -1;
best.len = 0;
cur.base = -1;

View File

@@ -72,7 +72,7 @@ json_expand_buf(struct json_container *jsonc)
static bool
json_new_line(struct json_container *jsonc)
{
int indent = jsonc->indent_level;
unsigned int indent = jsonc->indent_level;
debug_decl(json_new_line, SUDO_DEBUG_UTIL);
/* No non-essential white space in minimal mode. */

View File

@@ -220,7 +220,7 @@ sudo_lbuf_append_quoted_v1(struct sudo_lbuf *lbuf, const char *set, const char *
bool ret = false;
const char *cp, *s;
va_list ap;
int len;
unsigned int len;
debug_decl(sudo_lbuf_append_quoted, SUDO_DEBUG_UTIL);
if (sudo_lbuf_error(lbuf))
@@ -358,11 +358,11 @@ done:
/* XXX - check output function return value */
static void
sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, size_t len)
{
char *cp, save;
int i, have, contlen = 0;
int indent = lbuf->indent;
size_t i, have, contlen = 0;
unsigned int indent = lbuf->indent;
bool is_comment = false;
debug_decl(sudo_lbuf_println, SUDO_DEBUG_UTIL);
@@ -382,14 +382,14 @@ sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
have = lbuf->cols;
while (cp != NULL && *cp != '\0') {
char *ep = NULL;
int need = len - (int)(cp - line);
size_t need = len - (cp - line);
if (need > have) {
have -= contlen; /* subtract for continuation char */
if ((ep = memrchr(cp, ' ', have)) == NULL)
ep = memchr(cp + have, ' ', need - have);
if (ep != NULL)
need = (int)(ep - cp);
need = (ep - cp);
}
if (cp != line) {
if (is_comment) {
@@ -436,7 +436,7 @@ void
sudo_lbuf_print_v1(struct sudo_lbuf *lbuf)
{
char *cp, *ep;
int len;
size_t len;
debug_decl(sudo_lbuf_print, SUDO_DEBUG_UTIL);
if (lbuf->buf == NULL || lbuf->len == 0)
@@ -460,7 +460,7 @@ sudo_lbuf_print_v1(struct sudo_lbuf *lbuf)
} else {
len = lbuf->len - (cp - lbuf->buf);
if ((ep = memchr(cp, '\n', len)) != NULL)
len = (int)(ep - cp);
len = (size_t)(ep - cp);
if (len)
sudo_lbuf_println(lbuf, cp, len);
cp = ep ? ep + 1 : NULL;

View File

@@ -34,7 +34,7 @@ sudo_dso_public int main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
unsigned int i;
size_t i;
#include "mksiglist.h"
@@ -43,10 +43,10 @@ main(int argc, char *argv[])
if (sudo_sys_siglist[i] != NULL) {
printf(" \"%s\",\n", sudo_sys_siglist[i]);
} else {
printf(" \"Signal %u\",\n", i);
printf(" \"Signal %zu\",\n", i);
}
}
printf("};\n");
exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}

View File

@@ -34,7 +34,7 @@ sudo_dso_public int main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
unsigned int i;
size_t i;
#include "mksigname.h"
@@ -43,10 +43,10 @@ main(int argc, char *argv[])
if (sudo_sys_signame[i] != NULL) {
printf(" \"%s\",\n", sudo_sys_signame[i]);
} else {
printf(" \"Signal %u\",\n", i);
printf(" \"Signal %zu\",\n", i);
}
}
printf("};\n");
exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}

View File

@@ -56,7 +56,7 @@ sudo_stat_multiarch_v1(const char *path, struct stat *sb)
const char **lp, *lib, *slash;
struct utsname unamebuf;
char *newpath = NULL;
int len;
size_t len;
if (uname(&unamebuf) == -1)
return NULL;
@@ -79,9 +79,8 @@ sudo_stat_multiarch_v1(const char *path, struct stat *sb)
}
/* Add machine-linux-gnu dir after /lib/ or /libexec/. */
len = asprintf(&newpath, "%.*s%s%s-linux-gnu%s",
(int)(lib - path), path, newlib, unamebuf.machine, slash);
if (len == -1) {
if (asprintf(&newpath, "%.*s%s%s-linux-gnu%s",
(int)(lib - path), path, newlib, unamebuf.machine, slash) == -1) {
newpath = NULL;
break;
}

View File

@@ -61,7 +61,7 @@ void
initprogname2(const char *name, const char * const * allowed)
{
const char *progname;
int i;
size_t i;
/* Fall back on "name" if getprogname() returns an empty string. */
if ((progname = getprogname()) != NULL && *progname != '\0') {

View File

@@ -87,7 +87,7 @@ sudo_sig2str(int signo, char *signame)
strlcpy(signame, cp, SIG2STR_MAX);
/* Make sure we always return an upper case signame. */
if (islower((unsigned char)signame[0])) {
int i;
size_t i;
for (i = 0; signame[i] != '\0'; i++)
signame[i] = toupper((unsigned char)signame[i]);
}

View File

@@ -107,7 +107,7 @@ union arg {
};
static int __find_arguments(const char *fmt0, va_list ap, union arg **argtable);
static int __grow_type_table(unsigned char **typetable, int *tablesize);
static int __grow_type_table(unsigned char **typetable, long *tablesize);
static int xxxprintf(char **, size_t, int, const char *, va_list);
#ifdef PRINTF_WIDE_CHAR
@@ -1089,9 +1089,9 @@ __find_arguments(const char *fmt0, va_list ap, union arg **argtable)
int flags; /* flags as above */
unsigned char *typetable; /* table of types */
unsigned char stattypetable[STATIC_ARG_TBL_SIZE];
int tablesize; /* current size of type table */
int tablemax; /* largest used index in table */
int nextarg; /* 1-based argument index */
long tablesize; /* current size of type table */
long tablemax; /* largest used index in table */
long nextarg; /* 1-based argument index */
int ret = 0; /* return value */
/*
@@ -1421,13 +1421,14 @@ finish:
* Increase the size of the type table.
*/
static int
__grow_type_table(unsigned char **typetable, int *tablesize)
__grow_type_table(unsigned char **typetable, long *tablesize)
{
unsigned char *oldtable = *typetable;
int newsize = *tablesize * 2;
long newsize = *tablesize * 2;
long size = sysconf(_SC_PAGESIZE);
if (newsize < sysconf(_SC_PAGESIZE))
newsize = sysconf(_SC_PAGESIZE);
if (newsize < size)
newsize = size;
if (*tablesize == STATIC_ARG_TBL_SIZE) {
*typetable = sudo_mmap_alloc(newsize);

View File

@@ -377,8 +377,8 @@ parse_plugin(const char *entry, const char *conf_file, unsigned int lineno)
oom:
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
if (options != NULL) {
while (nopts--)
free(options[nopts]);
while (nopts)
free(options[--nopts]);
free(options);
}
if (info != NULL) {
@@ -575,7 +575,7 @@ sudo_conf_init(int conf_types)
struct sudo_conf_debug *debug_spec;
struct sudo_debug_file *debug_file;
struct plugin_info *plugin_info;
int i;
size_t i;
debug_decl(sudo_conf_init, SUDO_DEBUG_UTIL);
/* Free and reset paths. */
@@ -717,7 +717,7 @@ sudo_conf_read_v1(const char *path, int conf_types)
while (sudo_parseln(&line, &linesize, &conf_lineno, fp, 0) != -1) {
struct sudo_conf_table *cur;
unsigned int i;
size_t i;
char *cp;
if (*(cp = line) == '\0')

View File

@@ -252,7 +252,7 @@ sudo_term_copy_v1(int src, int dst)
struct termios tt_src, tt_dst;
struct winsize wsize;
speed_t speed;
int i;
unsigned int i;
debug_decl(sudo_term_copy, SUDO_DEBUG_UTIL);
if (tcgetattr(src, &tt_src) != 0 || tcgetattr(dst, &tt_dst) != 0)

View File

@@ -75,7 +75,7 @@ sudo_uuid_to_string_v1(unsigned char uuid[16], char *dst, size_t dstsiz)
{
const char hex[] = "0123456789abcdef";
char *cp = dst;
int i;
unsigned int i;
if (dstsiz < sizeof("123e4567-e89b-12d3-a456-426655440000"))
return NULL;