changeset 38494:768a739698d5

nap.h: Fix logic. * tests/nap.h (nap): Avoid signed integer overflow in loop.
author Bruno Haible <bruno@clisp.org>
date Sun, 23 Apr 2017 19:09:32 +0200
parents 238ae8192e65
children 0a8461cb40bb
files ChangeLog tests/nap.h
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Apr 23 19:02:08 2017 +0200
+++ b/ChangeLog	Sun Apr 23 19:09:32 2017 +0200
@@ -1,3 +1,8 @@
+2017-04-23  Bruno Haible  <bruno@clisp.org>
+
+	nap.h: Fix logic.
+	* tests/nap.h (nap): Avoid signed integer overflow in loop.
+
 2017-04-23  Bruno Haible  <bruno@clisp.org>
 
 	Fix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.
--- a/tests/nap.h	Sun Apr 23 19:02:08 2017 +0200
+++ b/tests/nap.h	Sun Apr 23 19:09:32 2017 +0200
@@ -117,9 +117,18 @@
     delay = delay / 2;  /* Try half of the previous delay.  */
   ASSERT (0 < delay);
 
-  for ( ; delay <= 2147483647; delay = delay * 2)
-    if (nap_works (nap_fd, delay, old_st))
-      return;
+  for (;;)
+    {
+      if (nap_works (delay, old_st))
+        return;
+      if (delay <= (2147483647 - 1) / 2)
+        {
+          delay = delay * 2 + 1;
+          continue;
+        }
+      else
+        break;
+    }
 
   /* Bummer: even the highest nap delay didn't work. */
   ASSERT (0);