]> Savannah Git Hosting - gnulib.git/commitdiff
maint: fix overflow checking in nap.h
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 26 Sep 2017 01:20:44 +0000 (18:20 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 26 Sep 2017 01:28:31 +0000 (18:28 -0700)
* modules/chown-tests:
* modules/fchownat-tests, modules/fdutimensat-tests:
* modules/futimens-tests, modules/lchown-tests:
* modules/stat-time-tests, modules/utime-tests:
* modules/utimens-tests, modules/utimensat-tests:
Depend on intprops.
* tests/nap.h: Include intprops.h.
(diff_timespec): Handle overflow properly.

ChangeLog
modules/chown-tests
modules/fchownat-tests
modules/fdutimensat-tests
modules/futimens-tests
modules/lchown-tests
modules/stat-time-tests
modules/utime-tests
modules/utimens-tests
modules/utimensat-tests
tests/nap.h

index 0995e5d5398006c928de8ba4cc8080473f160fc3..9935941df23ba4121d88f6186a8fec9422c9a5db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-09-25  Paul Eggert  <eggert@cs.ucla.edu>
 
+       maint: fix overflow checking in nap.h
+       * modules/chown-tests:
+       * modules/fchownat-tests, modules/fdutimensat-tests:
+       * modules/futimens-tests, modules/lchown-tests:
+       * modules/stat-time-tests, modules/utime-tests:
+       * modules/utimens-tests, modules/utimensat-tests:
+       Depend on intprops.
+       * tests/nap.h: Include intprops.h.
+       (diff_timespec): Handle overflow properly.
+
        sys_types: update URL
        * m4/sys_types_h.m4: Use https: URL.
 
index 58b96568212ba9d4ca4f4e4035f072ffbcc0f126..13138f438b568a798451a716e6b6488b145c20eb 100644 (file)
@@ -7,6 +7,7 @@ tests/macros.h
 
 Depends-on:
 ignore-value
+intprops
 lstat
 mgetgroups
 nanosleep
index 4e289bda5d9f3fff45a13f4a97f1401fd0d4017a..81adf7fe83fe60c2e207a4c8c2cbd3e0b1f306e4 100644 (file)
@@ -8,6 +8,7 @@ tests/macros.h
 
 Depends-on:
 ignore-value
+intprops
 mgetgroups
 nanosleep
 openat-h
index a77ada4f0616940bff5f9e462b724d567c2d1a6b..37f70c652824a9f9563a1f8dd446f54a17c5ab20 100644 (file)
@@ -10,6 +10,7 @@ tests/macros.h
 Depends-on:
 fcntl-h
 ignore-value
+intprops
 nanosleep
 openat
 timespec
index c7e9db2f01beb4ff68dd03cd95d2bdead681ca11..519141300733aa77cbcf1db875d4dfed589b4984 100644 (file)
@@ -10,6 +10,7 @@ Depends-on:
 gettext-h
 fcntl-h
 ignore-value
+intprops
 nanosleep
 timespec
 dup
index d7288fea6cdf69c7000a514c44a1f6af1f8a1ad4..c5bba89d50681a71cc55f445385c4c35ef762b4d 100644 (file)
@@ -7,6 +7,7 @@ tests/macros.h
 
 Depends-on:
 ignore-value
+intprops
 mgetgroups
 nanosleep
 stat-time
index 18843de5a63f422f3d57f86199e61b51a0e23e65..c512eca76c5bde761dd1581703b7a0494fdc8144 100644 (file)
@@ -4,6 +4,7 @@ tests/macros.h
 tests/nap.h
 
 Depends-on:
+intprops
 nanosleep
 time
 
index 1d3da120e98de88b8fba4114f7ee27b2b75647e0..a64d0a0069096c819c220587c36d16114670381a 100644 (file)
@@ -8,6 +8,7 @@ Depends-on:
 dup
 gettext-h
 ignore-value
+intprops
 nanosleep
 symlink
 timespec
index d5e3085d277de8a9160489ad76179e1c9ba1253e..2a95346a0d09b7e4343f34e8bba5372db3f3fd11 100644 (file)
@@ -11,6 +11,7 @@ Depends-on:
 dup
 gettext-h
 ignore-value
+intprops
 nanosleep
 symlink
 timespec
index 09e5cb15bfb433b2ef1ffc86e661277604754ef9..15c79407e8d08d0a4fdc4bad779a4db49114b73b 100644 (file)
@@ -9,6 +9,7 @@ tests/macros.h
 
 Depends-on:
 ignore-value
+intprops
 nanosleep
 timespec
 utimecmp
index c16ee904e6a4abf79979de08e8010c5d6db6aea3..24043c6121368582d8f00c9f8183c0bb3fe28bf5 100644 (file)
@@ -22,6 +22,8 @@
 # include <limits.h>
 # include <stdbool.h>
 
+# include <intprops.h>
+
 /* Name of the witness file.  */
 #define TEMPFILE BASE "nap.tmp"
 
@@ -38,17 +40,20 @@ diff_timespec (struct timespec a, struct timespec b)
   time_t bs = b.tv_sec;
   int ans = a.tv_nsec;
   int bns = b.tv_nsec;
+  int sdiff;
+
+  ASSERT (0 <= ans && ans < 2000000000);
+  ASSERT (0 <= bns && bns < 2000000000);
 
   if (! (bs < as || (bs == as && bns < ans)))
     return 0;
-  if (as - bs <= INT_MAX / 1000000000)
-    {
-      int sdiff = (as - bs) * 1000000000;
-      int usdiff = ans - bns;
-      if (usdiff < INT_MAX - sdiff)
-        return sdiff + usdiff;
-    }
-  return INT_MAX;
+
+  if (INT_SUBTRACT_WRAPV (as, bs, &sdiff)
+      || INT_MULTIPLY_WRAPV (sdiff, 1000000000, &sdiff)
+      || INT_ADD_WRAPV (sdiff, ans - bns, &sdiff))
+    return INT_MAX;
+
+  return sdiff;
 }
 
 /* If DO_WRITE, bump the modification time of the file designated by NAP_FD.