[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fix nap.h logic
From: |
Bruno Haible |
Subject: |
fix nap.h logic |
Date: |
Tue, 25 Apr 2017 00:04:25 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-72-generic; KDE/5.18.0; x86_64; ; ) |
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 <address@hidden>
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 Thread] |
Current Thread |
[Next in Thread] |
- fix nap.h logic,
Bruno Haible <=