]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: avoid -Werror=strict-overflow warnings with GCC 5
authorPádraig Brady <P@draigBrady.com>
Wed, 22 Apr 2015 00:07:01 +0000 (01:07 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 22 Apr 2015 10:11:19 +0000 (11:11 +0100)
All warnings were of the form: "assuming signed overflow does not occur
when simplifying conditional to constant [-Werror=strict-overflow]"

* src/dd.c (cache_round): Use an appropriately sized unsigned type,
to avoid possibility of undefined signed overflow.
* src/mknod.c (main): Likewise.
* src/pr.c (pad_down): Likewise.
* src/wc.c (main): Likewise.
* src/tail.c (main): Assert that argc >= 0 thus allowing the
compiler to assume without implication that argc - optind
is positive.

src/dd.c
src/mknod.c
src/pr.c
src/tail.c
src/wc.c

index e78f2a290a9a7a5e816ce6ff9b937365db4b758f..321b096d4492b3311d02d1097508cc041075bd94 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -987,7 +987,7 @@ cache_round (int fd, off_t len)
 
   if (len)
     {
-      off_t c_pending = *pending + len;
+      uintmax_t c_pending = *pending + len;
       *pending = c_pending % page_size;
       if (c_pending > *pending)
         len = c_pending - *pending;
index 2804aaf7c48970c1728978f062022f6637c9f4da..73342ce2942a1f1cd0b58574cfdd32994934f71e 100644 (file)
@@ -94,7 +94,7 @@ main (int argc, char **argv)
   mode_t newmode;
   char const *specified_mode = NULL;
   int optc;
-  int expected_operands;
+  size_t expected_operands;
   mode_t node_type;
   char const *scontext = NULL;
   bool set_security_context = false;
index 78fe697998dc41d1c78f12d1a088f6b74f8e20ef..6ff51ec5ac2b00183a5ea1bc50d66794cd0c11ef 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -438,7 +438,7 @@ static void init_store_cols (void);
 static void store_columns (void);
 static void balance (int total_stored);
 static void store_char (char c);
-static void pad_down (int lines);
+static void pad_down (unsigned int lines);
 static void read_rest_of_line (COLUMN *p);
 static void skip_read (COLUMN *p, int column_number);
 static void print_char (char c);
@@ -2052,9 +2052,9 @@ pad_across_to (int position)
    Otherwise, use newlines. */
 
 static void
-pad_down (int lines)
+pad_down (unsigned int lines)
 {
-  int i;
+  unsigned int i;
 
   if (use_form_feed)
     putchar ('\f');
index f75d7a9eed787aa00e10aaa0a7bbca6140c4ef99..b29dab1c9f95d652432ee59c12f7ce7d1c17c929 100644 (file)
@@ -2180,6 +2180,8 @@ main (int argc, char **argv)
         --n_units;
     }
 
+  IF_LINT (assert (0 <= argc));
+
   if (optind < argc)
     {
       n_files = argc - optind;
index 91f4a3145525a132c0bec2ba76bad20ad9509890..fe73d2ce162931cafacdec602b6fdb1582433f44 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -558,7 +558,7 @@ wc_file (char const *file, struct fstatus *fstatus)
    that happens when we don't know how long the list of file names will be.  */
 
 static struct fstatus *
-get_input_fstatus (int nfiles, char *const *file)
+get_input_fstatus (size_t nfiles, char *const *file)
 {
   struct fstatus *fstatus = xnmalloc (nfiles ? nfiles : 1, sizeof *fstatus);
 
@@ -570,7 +570,7 @@ get_input_fstatus (int nfiles, char *const *file)
     fstatus[0].failed = 1;
   else
     {
-      int i;
+      size_t i;
 
       for (i = 0; i < nfiles; i++)
         fstatus[i].failed = (! file[i] || STREQ (file[i], "-")
@@ -586,7 +586,7 @@ get_input_fstatus (int nfiles, char *const *file)
    get_input_fstatus optimizes.  */
 
 static int _GL_ATTRIBUTE_PURE
-compute_number_width (int nfiles, struct fstatus const *fstatus)
+compute_number_width (size_t nfiles, struct fstatus const *fstatus)
 {
   int width = 1;
 
@@ -594,7 +594,7 @@ compute_number_width (int nfiles, struct fstatus const *fstatus)
     {
       int minimum_width = 1;
       uintmax_t regular_total = 0;
-      int i;
+      size_t i;
 
       for (i = 0; i < nfiles; i++)
         if (! fstatus[i].failed)
@@ -620,7 +620,7 @@ main (int argc, char **argv)
 {
   bool ok;
   int optc;
-  int nfiles;
+  size_t nfiles;
   char **files;
   char *files_from = NULL;
   struct fstatus *fstatus;