coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] maint: avoid -Werror=strict-overflow warnings with GCC 5


From: Pádraig Brady
Subject: [PATCH] maint: avoid -Werror=strict-overflow warnings with GCC 5
Date: Wed, 22 Apr 2015 01:17:31 +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
doesn't wrap.
---
 src/dd.c    |  2 +-
 src/mknod.c |  2 +-
 src/pr.c    |  6 +++---
 src/tail.c  |  2 ++
 src/wc.c    | 10 +++++-----
 5 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index e78f2a2..321b096 100644
--- 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;
diff --git a/src/mknod.c b/src/mknod.c
index 2804aaf..73342ce 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -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;
diff --git a/src/pr.c b/src/pr.c
index 78fe697..6ff51ec 100644
--- 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');
diff --git a/src/tail.c b/src/tail.c
index f75d7a9..b29dab1 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -2180,6 +2180,8 @@ main (int argc, char **argv)
         --n_units;
     }
 
+  IF_LINT (assert (0 <= argc));
+
   if (optind < argc)
     {
       n_files = argc - optind;
diff --git a/src/wc.c b/src/wc.c
index 91f4a31..fe73d2c 100644
--- 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;
-- 
2.3.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]