Make xnanosleep's integer overflow test more robust.
authorJim Meyering <meyering@redhat.com>
Sun, 7 Oct 2007 18:49:20 +0000 (20:49 +0200)
committerJim Meyering <meyering@redhat.com>
Sun, 7 Oct 2007 18:55:17 +0000 (20:55 +0200)
* lib/xnanosleep.c (xnanosleep): Declare a temporary to be "volatile",
so that gcc-4.3.0 doesn't optimize away this test for overflow.

Signed-off-by: Jim Meyering <meyering@redhat.com>
ChangeLog
lib/xnanosleep.c

index 7401df0..275e2ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-10-07  Jim Meyering  <meyering@redhat.com>
+
+       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.
+
 2007-10-07  Bruno Haible  <bruno@clisp.org>
 
        * doc/gnulib-intro.texi (Copyright): Update the meaning of the license
index 6a61ddb..22bd53a 100644 (file)
@@ -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);