[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Make xnanosleep's integer overflow test more robust
From: |
Jim Meyering |
Subject: |
Make xnanosleep's integer overflow test more robust |
Date: |
Sun, 07 Oct 2007 20:56:36 +0200 |
I noticed a new warning, when compiling with
gcc version 4.3.0 20071004 (experimental) (GCC)
xnanosleep.c:79: warning: assuming signed overflow does not occur
when assuming that (X + c) < X is always false
Here's what I've just pushed:
2007-10-07 Jim Meyering <address@hidden>
Make xnanosleep's integer overflow test more robust.
* lib/xnanosleep.c (xnanosleep): Declare a temporary to be "volatile",
so that gcc-4.3.0 doesn't optimize away this test for overflow.
...
diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c
index 6a61ddb..22bd53a 100644
--- a/lib/xnanosleep.c
+++ b/lib/xnanosleep.c
@@ -72,7 +72,9 @@ xnanosleep (double seconds)
/* Normalize the interval length. nanosleep requires this. */
if (BILLION <= ts_sleep.tv_nsec)
{
- time_t t = ts_sleep.tv_sec + 1;
+ /* Declare "volatile" so that gcc-4.3.0 doesn't optimize away
+ the overflow test. */
+ volatile time_t t = ts_sleep.tv_sec + 1;
/* Detect integer overflow. */
overflow |= (t < ts_sleep.tv_sec);
--
1.5.3.4.206.g58ba4
- Make xnanosleep's integer overflow test more robust,
Jim Meyering <=