more -Wall warning fixes from Cristian Ionescu-Idbohrn.
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 13 May 2008 02:27:31 +0000 (02:27 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 13 May 2008 02:27:31 +0000 (02:27 -0000)
This time it resulted in small code changes:

function                                             old     new   delta
nexpr                                                820     828      +8
tail_main                                           1200    1202      +2
wrapf                                                166     167      +1
parse_mount_options                                  227     209     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 11/-18)             Total: -7 bytes

27 files changed:
archival/libunarchive/get_header_tar.c
coreutils/basename.c
coreutils/cut.c
coreutils/dd.c
coreutils/expand.c
coreutils/sort.c
coreutils/stty.c
coreutils/tail.c
coreutils/test.c
coreutils/tr.c
debianutils/start_stop_daemon.c
editors/awk.c
editors/sed.c
editors/vi.c
findutils/xargs.c
libbb/lineedit.c
libbb/md5.c
libbb/read.c
libbb/u_signal_names.c
libbb/xfuncs_printf.c
miscutils/crond.c
miscutils/eject.c
util-linux/mdev.c
util-linux/mount.c
util-linux/switch_root.c
util-linux/volume_id/util.c
util-linux/volume_id/volume_id.c

index 29aed184c19c1bd65ec6dd26816e6bb693e8c4c9..0be29b7cecaf6507bcce5747cb7d1591efba20a3 100644 (file)
@@ -138,12 +138,12 @@ char get_header_tar(archive_handle_t *archive_handle)
                /* tar gz/bz autodetect: check for gz/bz2 magic.
                 * If it is the very first block, and we see the magic,
                 * we can switch to get_header_tar_gz/bz2/lzma().
-                * Needs seekable fd. I wish recv(MSG_PEEK) would work
+                * Needs seekable fd. I wish recv(MSG_PEEK) works
                 * on any fd... */
                if (not_first)
                        goto err;
 #if ENABLE_FEATURE_TAR_GZIP
-               if (tar.name[0] == 0x1f && tar.name[1] == 0x8b) { /* gzip */
+               if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
                        get_header_ptr = get_header_tar_gz;
                } else
 #endif
index 2216182e0feb94eb8312010fd6c26cc8d7f48e14..a3085ede3079eded33e0f901725f06f1937c5416 100644 (file)
@@ -48,5 +48,5 @@ int basename_main(int argc, char **argv)
 
        /* puts(s) will do, but we can do without stdio this way: */
        s[m++] = '\n';
-       return full_write(STDOUT_FILENO, s, m) == m;
+       return full_write(STDOUT_FILENO, s, m) == (ssize_t)m;
 }
index 7a44d10886442770b2542619fec581cf4f8c433d..1634fc8c8e080bb05c87bd5fd107118d55c17db1 100644 (file)
@@ -64,7 +64,7 @@ static void cut_file(FILE *file, char delim)
                        /* print the chars specified in each cut list */
                        for (; cl_pos < nlists; cl_pos++) {
                                spos = cut_lists[cl_pos].startpos;
-                               while (spos < strlen(line)) {
+                               while (spos < (int)strlen(line)) {
                                        if (!printed[spos]) {
                                                printed[spos] = 'X';
                                                putchar(line[spos]);
@@ -80,12 +80,12 @@ static void cut_file(FILE *file, char delim)
 
                        /* get out if we have no more lists to process or if the lines
                         * are lower than what we're interested in */
-                       if (linenum < spos || cl_pos >= nlists)
+                       if (((int)linenum < spos) || (cl_pos >= nlists))
                                goto next_line;
 
                        /* if the line we're looking for is lower than the one we were
                         * passed, it means we displayed it already, so move on */
-                       while (spos < linenum) {
+                       while (spos < (int)linenum) {
                                spos++;
                                /* go to the next list if we're at the end of this one */
                                if (spos > cut_lists[cl_pos].endpos
@@ -97,7 +97,7 @@ static void cut_file(FILE *file, char delim)
                                        spos = cut_lists[cl_pos].startpos;
                                        /* get out if the current line is lower than the one
                                         * we just became interested in */
-                                       if (linenum < spos)
+                                       if ((int)linenum < spos)
                                                goto next_line;
                                }
                        }
index 4d1ef0b76434fe46ea5e71e0d11226574bd1d47e..6b66366b60d363ab3584be6ba1854a23cb1a94c5 100644 (file)
@@ -65,7 +65,7 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
        ssize_t n = full_write_or_warn(buf, len, filename);
        if (n < 0)
                return 1;
-       if (n == obs)
+       if ((size_t)n == obs)
                G.out_full++;
        else if (n) /* > 0 */
                G.out_part++;
@@ -312,7 +312,7 @@ int dd_main(int argc ATTRIBUTE_UNUSED, char **argv)
                        while (n) {
                                size_t d = obs - oc;
 
-                               if (d > n)
+                               if (d > (size_t)n)
                                        d = n;
                                memcpy(obuf + oc, tmp, d);
                                n -= d;
index a7ac8ea84acc58b0e9e74acbc5ebe5fb0b1d12c7..af2ef8675a249336b1d5b7b90a8e6279a4ae4714 100644 (file)
@@ -41,7 +41,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt)
        char *line;
        char *ptr;
        int convert;
-       int pos;
+       unsigned pos;
 
        /* Increment tab_size by 1 locally.*/
        tab_size++;
@@ -80,7 +80,7 @@ static void unexpand(FILE *file, unsigned int tab_size, unsigned opt)
        int convert;
        int pos;
        int i = 0;
-       int column = 0;
+       unsigned column = 0;
 
        while ((line = xmalloc_fgets(file)) != NULL) {
                convert = 1;
index a54be7269a8be9eeeafff00a2bf4bc1cf0ddb1dd..12b463a6d0f1db1f345befbd56044996d3e67657 100644 (file)
@@ -59,7 +59,8 @@ static struct sort_key {
 
 static char *get_key(char *str, struct sort_key *key, int flags)
 {
-       int start = 0, end = 0, len, i, j;
+       int start = 0, end = 0, len, j;
+       unsigned i;
 
        /* Special case whole string, so we don't have to make a copy */
        if (key->range[0] == 1 && !key->range[1] && !key->range[2] && !key->range[3]
index 298fb5b70b18a5ae0fa1fb89f39e91632b4c0777..a17955a6a3bacb8e176f01271f8323efbe309fbb 100644 (file)
@@ -710,7 +710,7 @@ static void wrapf(const char *message, ...)
 {
        char buf[128];
        va_list args;
-       int buflen;
+       unsigned buflen;
 
        va_start(args, message);
        buflen = vsnprintf(buf, sizeof(buf), message, args);
index 2f997a9f6c61e788a72ecf072ccd457fdc3810b9..2505fc3a604d5c9bf1417350334b41c67e890ff9 100644 (file)
@@ -92,7 +92,8 @@ int tail_main(int argc, char **argv)
        size_t tailbufsize;
        int taillen = 0;
        int newlines_seen = 0;
-       int nfiles, nread, nwrite, seen, i, opt;
+       int nfiles, nread, nwrite, i, opt;
+       unsigned seen;
 
        int *fds;
        char *s, *buf;
@@ -210,7 +211,7 @@ int tail_main(int argc, char **argv)
                        } else if (count) {
                                if (COUNT_BYTES) {
                                        taillen += nread;
-                                       if (taillen > count) {
+                                       if (taillen > (int)count) {
                                                memmove(tailbuf, tailbuf + taillen - count, count);
                                                taillen = count;
                                        }
@@ -225,7 +226,7 @@ int tail_main(int argc, char **argv)
                                                }
                                        } while (k);
 
-                                       if (newlines_seen + newlines_in_buf < count) {
+                                       if (newlines_seen + newlines_in_buf < (int)count) {
                                                newlines_seen += newlines_in_buf;
                                                taillen += nread;
                                        } else {
@@ -243,7 +244,7 @@ int tail_main(int argc, char **argv)
                                                memmove(tailbuf, s, taillen);
                                                newlines_seen = count - extra;
                                        }
-                                       if (tailbufsize < taillen + BUFSIZ) {
+                                       if (tailbufsize < (size_t)taillen + BUFSIZ) {
                                                tailbufsize = taillen + BUFSIZ;
                                                tailbuf = xrealloc(tailbuf, tailbufsize);
                                        }
index 3c725a2454f09b19cc153521c994817429c10609..270ca21a938faec8e81382fdf1f30b1a6c2ef791 100644 (file)
@@ -412,7 +412,7 @@ static int test_eaccess(char *path, int mode)
 static int filstat(char *nm, enum token mode)
 {
        struct stat s;
-       int i = i; /* gcc 3.x thinks it can be used uninitialized */
+       unsigned i = i; /* gcc 3.x thinks it can be used uninitialized */
 
        if (mode == FILSYM) {
 #ifdef S_IFLNK
index 0d328490015e45804edecafa0084b16b4588c326..8b2d30802454b041ac43590a07c23f606e12d8fc 100644 (file)
@@ -219,7 +219,7 @@ int tr_main(int argc ATTRIBUTE_UNUSED, char **argv)
 
        for (;;) {
                /* If we're out of input, flush output and read more input. */
-               if (in_index == read_chars) {
+               if ((ssize_t)in_index == read_chars) {
                        if (out_index) {
                                xwrite(STDOUT_FILENO, (char *)output, out_index);
                                out_index = 0;
index 467deed481ef60aecc43397887d4a913fa1338d1..094b3b18a485729fa31a041cb5ccda549b080704 100644 (file)
@@ -126,7 +126,7 @@ static int pid_is_user(int pid)
        sprintf(buf, "/proc/%u", pid);
        if (stat(buf, &sb) != 0)
                return 0;
-       return (sb.st_uid == user_id);
+       return (sb.st_uid == (uid_t)user_id);
 }
 
 static int pid_is_cmd(pid_t pid)
index f04ea5ced2ad2d47bb3e7818d69545feac1458ff..fef3246b87b02f6cba3b9f1740db73e935f26f0c 100644 (file)
@@ -676,7 +676,7 @@ static char nextchar(char **s)
        return c;
 }
 
-static int ALWAYS_INLINE isalnum_(int c)
+static ALWAYS_INLINE int isalnum_(int c)
 {
        return (isalnum(c) || c == '_');
 }
@@ -1682,7 +1682,7 @@ static void hashwalk_init(var *v, xhash *array)
 {
        char **w;
        hash_item *hi;
-       int i;
+       unsigned i;
 
        if (v->type & VF_WALK)
                free(v->x.walker);
@@ -1996,7 +1996,7 @@ static var *exec_builtin(node *op, var *res)
        }
 
        nargs = i;
-       if (nargs < (info >> 30))
+       if ((uint32_t)nargs < (info >> 30))
                syntax_error(EMSG_TOO_FEW_ARGS);
 
        switch (info & OPNMASK) {
index f858845349a73151e1ee26b46addfac4831ca6be..817840dc0180101ea722bc557853b9a6a4740141 100644 (file)
@@ -628,7 +628,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line)
 {
        char *oldline = *line;
        int altered = 0;
-       int match_count = 0;
+       unsigned match_count = 0;
        regex_t *current_regex;
 
        /* Handle empty regex. */
@@ -665,7 +665,9 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line)
 
                /* If we aren't interested in this match, output old line to
                   end of match and continue */
-               if (sed_cmd->which_match && sed_cmd->which_match != match_count) {
+               if (sed_cmd->which_match
+                && (sed_cmd->which_match != match_count)
+               ) {
                        for (i = 0; i < G.regmatch[0].rm_eo; i++)
                                pipe_putc(*oldline++);
                        continue;
index 4e5a5ac4a278ffc1afdb18d8487a095e21f25448..5013d0d5121c8c88d90375420a93a0ad4ff4ba3b 100644 (file)
@@ -2239,7 +2239,9 @@ static char readit(void)  // read (maybe cursor) key from stdin
                        pfd[0].events = POLLIN;
                        // keep reading while there are input chars, and room in buffer
                        // for a complete ESC sequence (assuming 8 chars is enough)
-                       while (safe_poll(pfd, 1, 0) > 0 && n <= (sizeof(readbuffer) - 8)) {
+                       while ((safe_poll(pfd, 1, 0) > 0)
+                        && ((size_t)n <= (sizeof(readbuffer) - 8))
+                       ) {
                                // read the rest of the ESC string
                                int r = safe_read(0, readbuffer + n, sizeof(readbuffer) - n);
                                if (r > 0)
index ee16ea675da26cd5f0c582735c52f45bc0793cfe..d1cf192b145fdea67020b5a3d820730be438678c 100644 (file)
@@ -233,7 +233,7 @@ static xlist_t *process_stdin(xlist_t *list_arg,
                }
                if (s == NULL)
                        s = p = buf;
-               if ((p - buf) >= mc)
+               if ((size_t)(p - buf) >= mc)
                        bb_error_msg_and_die("argument line too long");
                *p++ = (c == EOF ? '\0' : c);
                if (c == EOF) { /* word's delimiter or EOF detected */
index d1a7a4bac8d84c8a393945badfe303a385f73277..62dcc55cd2ba5785875582892133e058133c0d37 100644 (file)
@@ -262,7 +262,7 @@ static void input_backward(unsigned num)
                return;
        cursor -= num;
 
-       if (cmdedit_x >= num) {
+       if ((unsigned)cmdedit_x >= num) {
                cmdedit_x -= num;
                if (num <= 4) {
                        /* This is longer by 5 bytes on x86.
@@ -321,7 +321,7 @@ static void input_delete(int save)
 {
        int j = cursor;
 
-       if (j == command_len)
+       if (j == (int)command_len)
                return;
 
 #if ENABLE_FEATURE_EDITING_VI
@@ -830,7 +830,7 @@ static void input_tab(smallint *lastWasTab)
 
        if (!*lastWasTab) {
                char *tmp, *tmp1;
-               int len_found;
+               size_t len_found;
 /*             char matchBuf[MAX_LINELEN]; */
 #define matchBuf (S.input_tab__matchBuf)
                int find_type;
@@ -1787,7 +1787,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
                        if (vi_cmdmode)  /* Don't self-insert */
                                break;
 #endif
-                       if (command_len >= (maxsize - 2))        /* Need to leave space for enter */
+                       if ((int)command_len >= (maxsize - 2))        /* Need to leave space for enter */
                                break;
 
                        command_len++;
index 56f97270d008e8459a4783c869abfd9e191b1a44..8d4b9fe52cf6a6633e960a62bcbc88e593a28fd0 100644 (file)
@@ -383,7 +383,7 @@ void md5_hash(const void *buffer, size_t len, md5_ctx_t *ctx)
        // Process all input.
 
        while (len) {
-               int i = 64 - ctx->buflen;
+               unsigned i = 64 - ctx->buflen;
 
                // Copy data into aligned buffer.
 
index 288358d79bfbc9a9bc54692e85d5be0e52188bf0..fb903c18a06350d10cba7636448f713203642c50 100644 (file)
@@ -111,7 +111,7 @@ void xread(int fd, void *buf, size_t count)
 {
        if (count) {
                ssize_t size = full_read(fd, buf, count);
-               if (size != count)
+               if ((size_t)size != count)
                        bb_error_msg_and_die("short read");
        }
 }
@@ -160,7 +160,7 @@ char *xmalloc_reads(int fd, char *buf, size_t *maxsz_p)
 
        goto jump_in;
        while (sz < maxsz) {
-               if (p - buf == sz) {
+               if ((size_t)(p - buf) == sz) {
  jump_in:
                        buf = xrealloc(buf, sz + 128);
                        p = buf + sz;
index 97e9949e9dc9a77707de27124adbc771161ddb0c..7a0f75d6f1380c53df5572cb91b1f76dbb7ecbc3 100644 (file)
@@ -130,7 +130,7 @@ int get_signum(const char *name)
                return i;
        if (strncasecmp(name, "SIG", 3) == 0)
                name += 3;
-       for (i = 0; i < ARRAY_SIZE(signals); i++)
+       for (i = 0; (size_t)i < ARRAY_SIZE(signals); i++)
                if (strcasecmp(name, signals[i]) == 0)
                        return i;
 
@@ -172,7 +172,7 @@ void print_signames(void)
 {
        int signo;
 
-       for (signo = 1; signo < ARRAY_SIZE(signals); signo++) {
+       for (signo = 1; (size_t)signo < ARRAY_SIZE(signals); signo++) {
                const char *name = signals[signo];
                if (name[0])
                        puts(name);
index d3fb39f04a290a669d01bc44c266079d46d12532..105939b5ef3250699190ef991c089f5b3bf397f7 100644 (file)
@@ -204,7 +204,7 @@ void xwrite(int fd, const void *buf, size_t count)
 {
        if (count) {
                ssize_t size = full_write(fd, buf, count);
-               if (size != count)
+               if ((size_t)size != count)
                        bb_error_msg_and_die("short write");
        }
 }
index 98dd22d9d9a82546405e169fe127346ff1d6aa45..0b2d55822c93fc1dc6ba27a8d688f2412e942903 100644 (file)
@@ -145,7 +145,7 @@ static void crondlog(const char *ctl, ...)
        int level = (ctl[0] & 0x1f);
 
        va_start(va, ctl);
-       if (level >= LogLevel) {
+       if (level >= (int)LogLevel) {
                /* Debug mode: all to (non-redirected) stderr, */
                /* Syslog mode: all to syslog (logmode = LOGMODE_SYSLOG), */
                if (!DebugOpt && LogFile) {
@@ -423,7 +423,7 @@ static char *ParseField(char *user, char *ary, int modvalue, int off,
 
 static void FixDayDow(CronLine *line)
 {
-       int i;
+       size_t i;
        int weekUsed = 0;
        int daysUsed = 0;
 
index 91cf98f5fd6cfcc0326735effcc0e537c80ce713..aa22a3a42022dcf171148cd33cf8884f7a697a79 100644 (file)
@@ -38,7 +38,7 @@ static void eject_scsi(const char *dev)
                { START_STOP, 0, 0, 0, 2, 0 }
        };
 
-       int i;
+       unsigned i;
        unsigned char sense_buffer[32];
        unsigned char inqBuff[2];
        sg_io_hdr_t io_hdr;
index 4fff20dcd854e5dd7598dad4c36f78ece54f2cc0..14aa593f558c26c6c2b76a0d5c32b0c882288893 100644 (file)
@@ -120,8 +120,11 @@ static void make_device(char *path, int delete)
 
                                /* If not this device, skip rest of line */
                                /* (regexec returns whole pattern as "range" 0) */
-                               if (result || off[0].rm_so || off[0].rm_eo != strlen(device_name))
+                               if (result || off[0].rm_so
+                                || ((int)off[0].rm_eo != (int)strlen(device_name))
+                               ) {
                                        goto next_line;
+                               }
                        }
 
                        /* This line matches: stop parsing the file
index 4b8aea8c6468a6b78aec4c02e22d9fc26467eecb..292f877afa375cb0a28e767fbd1151376f807bd0 100644 (file)
@@ -307,7 +307,7 @@ static long parse_mount_options(char *options, char **unrecognized)
 
        // Loop through options
        for (;;) {
-               int i;
+               size_t i;
                char *comma = strchr(options, ',');
                const char *option_str = mount_option_str;
 
@@ -1004,7 +1004,7 @@ static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
                        bb_herror_msg("%s", hostname);
                        goto fail;
                }
-               if (hp->h_length > sizeof(struct in_addr)) {
+               if ((size_t)hp->h_length > sizeof(struct in_addr)) {
                        bb_error_msg("got bad hp->h_length");
                        hp->h_length = sizeof(struct in_addr);
                }
@@ -1279,15 +1279,14 @@ static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
                        if (hp == NULL) {
                                bb_herror_msg("%s", mounthost);
                                goto fail;
-                       } else {
-                               if (hp->h_length > sizeof(struct in_addr)) {
-                                       bb_error_msg("got bad hp->h_length?");
-                                       hp->h_length = sizeof(struct in_addr);
-                               }
-                               mount_server_addr.sin_family = AF_INET;
-                               memcpy(&mount_server_addr.sin_addr,
-                                               hp->h_addr, hp->h_length);
                        }
+                       if ((size_t)hp->h_length > sizeof(struct in_addr)) {
+                               bb_error_msg("got bad hp->h_length");
+                               hp->h_length = sizeof(struct in_addr);
+                       }
+                       mount_server_addr.sin_family = AF_INET;
+                       memcpy(&mount_server_addr.sin_addr,
+                                               hp->h_addr, hp->h_length);
                }
        }
 
index c030b99e187bd186a61e7d548e31ef599fd0c58b..bae695b0b6c39064f0d644f71fadbf36584b52f6 100644 (file)
 // Make up for header deficiencies.
 
 #ifndef RAMFS_MAGIC
-#define RAMFS_MAGIC            0x858458f6
+#define RAMFS_MAGIC ((unsigned)0x858458f6)
 #endif
 
 #ifndef TMPFS_MAGIC
-#define TMPFS_MAGIC            0x01021994
+#define TMPFS_MAGIC ((unsigned)0x01021994)
 #endif
 
 #ifndef MS_MOVE
-#define MS_MOVE                        8192
+#define MS_MOVE     8192
 #endif
 
 static dev_t rootdev;
@@ -91,10 +91,10 @@ int switch_root_main(int argc ATTRIBUTE_UNUSED, char **argv)
        // we mean it.  (I could make this a CONFIG option, but I would get email
        // from all the people who WILL eat their filesystems.)
 
-       if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs) ||
-               (stfs.f_type != RAMFS_MAGIC && stfs.f_type != TMPFS_MAGIC) ||
-               getpid() != 1)
-       {
+       if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs)
+        || (((unsigned)stfs.f_type != RAMFS_MAGIC) && ((unsigned)stfs.f_type != TMPFS_MAGIC))
+        || (getpid() != 1)
+       {
                bb_error_msg_and_die("not rootfs");
        }
 
index ce7de23fb27bb5b3f6567a37bf83a84f7e1386b4..240b3c1e37651357b7660d0c7729a58d15a7ad4a 100644 (file)
@@ -212,7 +212,7 @@ void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
                        }
                        dbg("got 0x%zx (%zi) bytes", buf_len, buf_len);
                        id->sbbuf_len = buf_len;
-                       if (buf_len < off + len) {
+                       if ((uint64_t)buf_len < off + len) {
                                dbg("requested 0x%zx bytes, got only 0x%zx bytes", len, buf_len);
                                return NULL;
                        }
@@ -243,7 +243,7 @@ void *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
                dbg("got 0x%zx (%zi) bytes", buf_len, buf_len);
                id->seekbuf_off = off;
                id->seekbuf_len = buf_len;
-               if (buf_len < len) {
+               if ((size_t)buf_len < len) {
                        dbg("requested 0x%zx bytes, got only 0x%zx bytes", len, buf_len);
                        return NULL;
                }
index de9aae2cea98cd2b987bba0ce116ccd0ed65c20f..aec96a26ebbb475c7e21984eb95df954d538c031 100644 (file)
@@ -152,7 +152,7 @@ static const probe_fptr fs2[] = {
 
 int volume_id_probe_all(struct volume_id *id, uint64_t off, uint64_t size)
 {
-       int i;
+       size_t i;
 
        if (id == NULL)
                return -EINVAL;