]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: accommodate gcc's -Wstrict-overflow option
authorJim Meyering <meyering@redhat.com>
Wed, 25 May 2011 10:29:18 +0000 (12:29 +0200)
committerJim Meyering <meyering@redhat.com>
Thu, 26 May 2011 20:13:37 +0000 (22:13 +0200)
* src/factor.c (factor_using_pollard_rho): Change type of "i"
to unsigned to avoid warning from gcc's -Wstrict-overflow.
* src/expr.c: Use an unsigned intermediate.
* src/dircolors.c (main): Reorder operations to avoid the risk of
pointer overflow.
* src/tr.c (squeeze_filter): Change NOT_A_CHAR from an anonymous
"enum" to an "int", to avoid this warning:
tr.c:1624:10: error: assuming signed overflow does not occur when
  simplifying conditional to constant [-Werror=strict-overflow]
* src/pr.c (main): Make index "i" unsigned.

src/dircolors.c
src/expr.c
src/factor.c
src/pr.c
src/tr.c

index d1962eae95aa2f4c7f21d21d3464b3c15eacb10d..9aaa87fc2b7d4a59adffd658619dc2cb6e8e83ae 100644 (file)
@@ -456,7 +456,7 @@ to select a shell syntax are mutually exclusive"));
   if (print_database)
     {
       char const *p = G_line;
-      while (p < G_line + sizeof G_line)
+      while (p - G_line < sizeof G_line)
         {
           puts (p);
           p += strlen (p) + 1;
index ce65ecf462e2b0f93efd8072a4174d3b43fdea83..2331f64fe2e1e2f5408b02d4c6b5dd0b74a2d483 100644 (file)
@@ -312,15 +312,17 @@ main (int argc, char **argv)
 
   parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
                       usage, AUTHORS, (char const *) NULL);
+
   /* The above handles --help and --version.
      Since there is no other invocation of getopt, handle `--' here.  */
-  if (argc > 1 && STREQ (argv[1], "--"))
+  unsigned int u_argc = argc;
+  if (1 < u_argc && STREQ (argv[1], "--"))
     {
-      --argc;
+      --u_argc;
       ++argv;
     }
 
-  if (argc <= 1)
+  if (u_argc <= 1)
     {
       error (0, 0, _("missing operand"));
       usage (EXPR_INVALID);
index 3354a4d5be4ca8935f41df037bdc9406a50a76de..27843201c86218fa21e31e7e1dbe0ec7e8956005 100644 (file)
@@ -160,7 +160,7 @@ factor_using_pollard_rho (mpz_t n, int a_int)
   mpz_t a;
   mpz_t g;
   mpz_t t1, t2;
-  int k, l, c, i;
+  int k, l, c;
 
   debug ("[pollard-rho (%d)] ", a_int);
 
@@ -204,6 +204,7 @@ S2:
       mpz_set (x1, x);
       k = l;
       l = 2 * l;
+      unsigned int i;
       for (i = 0; i < k; i++)
         {
           mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
index 7e6b13cc8ad2633f8df52a4db9c7f618fb6f5096..3995c37ce7382af32a1d43dfc73f74f958a96d4e 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -1165,7 +1165,7 @@ main (int argc, char **argv)
         print_files (n_files, file_names);
       else
         {
-          int i;
+          unsigned int i;
           for (i = 0; i < n_files; i++)
             print_files (1, &file_names[i]);
         }
index 2a729c696557952ab50e88e19f5dd76cf12d564f..f7593d3165f205e16f4923701f2f0551ff1795ed 100644 (file)
--- a/src/tr.c
+++ b/src/tr.c
@@ -1555,7 +1555,7 @@ squeeze_filter (char *buf, size_t size, size_t (*reader) (char *, size_t))
 {
   /* A value distinct from any character that may have been stored in a
      buffer as the result of a block-read in the function squeeze_filter.  */
-  enum { NOT_A_CHAR = CHAR_MAX + 1 };
+  const int NOT_A_CHAR = INT_MAX;
 
   int char_to_squeeze = NOT_A_CHAR;
   size_t i = 0;