[prev in list] [next in list] [prev in thread] [next in thread]
List: gnulib-bug
Subject: fix nap.h logic
From: Bruno Haible <bruno () clisp ! org>
Date: 2017-04-24 22:04:25
Message-ID: 2645110.4lLJQ9W3pq () omega
[Download RAW message or body]
With MSVC 14, test-utimens fails:
../../gltests/nap.h:69: assertion 'nanosleep (&delay_spec, 0) == 0' failed
Obviously a negative delay has been passed to nanosleep.
The code in nap.h is wrong: it multiplies the delay by 2, but a signed integer
eventually wraps around and becomes negative.
This fixes it.
2017-04-23 Bruno Haible <bruno@clisp.org>
nap.h: Fix logic.
* tests/nap.h (nap): Avoid signed integer overflow in loop.
diff --git a/tests/nap.h b/tests/nap.h
index b2726d7..ce8f95a 100644
--- a/tests/nap.h
+++ b/tests/nap.h
@@ -117,9 +117,18 @@ nap (void)
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);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic