From 1f9ee9c2dbc965ca2e2258c7bcda420b2ba3f764 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 7 Oct 2007 20:49:20 +0200 Subject: [PATCH] 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. Signed-off-by: Jim Meyering --- ChangeLog | 6 ++++++ lib/xnanosleep.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7401df0282..275e2ed5e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-10-07 Jim Meyering + + 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 * doc/gnulib-intro.texi (Copyright): Update the meaning of the license diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c index 6a61ddb0c3..22bd53a953 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); -- 2.30.2