]> Savannah Git Hosting - gnulib.git/commitdiff
utimecmp: avoid new GCC 7 warning from -Wbool-operation
authorJim Meyering <meyering@fb.com>
Wed, 5 Oct 2016 16:13:55 +0000 (09:13 -0700)
committerJim Meyering <meyering@fb.com>
Wed, 5 Oct 2016 16:14:44 +0000 (09:14 -0700)
Testing this module would fail when using GCC 7 like this:
$ CFLAGS='-O -Werror=bool-operation' ./gnulib-tool --create-testdir \
  --dir=/tmp/x --with-tests --test utimecmp
../../gllib/utimecmp.c: In function ‘utimecmp’:
../../gllib/utimecmp.c:291:36: error: ‘~’ on a boolean expression \
  [-Werror=bool-operation]
                 time_t s = src_s & ~ (res == 2 * BILLION);
                                    ^
../../gllib/utimecmp.c:370:16: error: ‘~’ on a boolean expression \
  [-Werror=bool-operation]
       src_s &= ~ (res == 2 * BILLION);
                ^
* lib/utimecmp.c (utimecmp): Do not apply "~" to a boolean.
Instead, make it explicit that we intend to apply it to 0 or 1.

ChangeLog
lib/utimecmp.c

index 93f83e6bed76a06b3f7e2ebd8e5e12bc76ef0f88..7b0417702844297b5abfed037fa0c40504a1a3a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2016-10-05  Jim Meyering  <meyering@fb.com>
+
+       utimecmp: avoid new GCC 7 warning from -Wbool-operation
+       Testing this module would fail when using GCC 7 like this:
+       $ CFLAGS='-O -Werror=bool-operation' ./gnulib-tool --create-testdir \
+         --dir=/tmp/x --with-tests --test utimecmp
+       ../../gllib/utimecmp.c: In function ‘utimecmp’:
+       ../../gllib/utimecmp.c:291:36: error: ‘~’ on a boolean expression \
+         [-Werror=bool-operation]
+                        time_t s = src_s & ~ (res == 2 * BILLION);
+                                           ^
+       ../../gllib/utimecmp.c:370:16: error: ‘~’ on a boolean expression \
+         [-Werror=bool-operation]
+              src_s &= ~ (res == 2 * BILLION);
+                       ^
+       * lib/utimecmp.c (utimecmp): Do not apply "~" to a boolean.
+       Instead, make it explicit that we intend to apply it to 0 or 1.
+
 2016-10-03  Pádraig Brady  <P@draigBrady.com>
 
        quotearg: minimize shell quoting using double quotes
index ac3d6262883ae9d211fbf68792239e3d925bfa89..c2e30579d688cad2b7914e943c7c374c0e3dd396 100644 (file)
@@ -288,7 +288,7 @@ utimecmp (char const *dst_name,
                  to interrogate the file system to deduce the exact time
                  stamp resolution; return the answer directly.  */
               {
-                time_t s = src_s & ~ (res == 2 * BILLION);
+                time_t s = src_s & ~ (res == 2 * BILLION ? 1 : 0);
                 if (src_s < dst_s || (src_s == dst_s && src_ns <= dst_ns))
                   return 1;
                 if (dst_s < s
@@ -367,7 +367,7 @@ utimecmp (char const *dst_name,
         }
 
       /* Truncate the source's time stamp according to the resolution.  */
-      src_s &= ~ (res == 2 * BILLION);
+      src_s &= ~ (res == 2 * BILLION ? 1 : 0);
       src_ns -= src_ns % res;
     }