From: Paul Eggert Date: Sun, 22 Dec 2019 20:38:22 +0000 (-0800) Subject: gethrxtime: remove incorrect overflow detection X-Git-Tag: v1.0~4433 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f935bab8ad7e94938c857b30d75582731db5595a;p=gnulib.git gethrxtime: remove incorrect overflow detection This is part of a patch written by Bruno Haible: https://lists.gnu.org/r/bug-gnulib/2019-12/msg00192.html * lib/xtime.h (xtime_make): Remove attempt to prevent internal integer overflow, as it didn’t suffice. This reverts the xtime.h part of 2018-10-12T04:46:09Z!akim.demaille@gmail.com, which I cannot now see the need for anyway (even in cases where it works), as the patch is helpful only when the signs of S and NS disagree, and all callers pass nonnegative values for S and NS. Instead, add a comment saying args should be nonnegative. --- diff --git a/ChangeLog b/ChangeLog index b5dedb14da..25c8c4755f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2019-12-22 Bruno Haible + + gethrxtime: remove incorrect overflow detection + * lib/xtime.h (xtime_make): Remove attempt to prevent internal + integer overflow, as it didn’t suffice. This reverts the xtime.h + part of 2018-10-12T04:46:09Z!akim.demaille@gmail.com, which I + cannot now see the need for anyway (even in cases where it works), + as the patch is helpful only when the signs of S and NS disagree, + and all callers pass nonnegative values for S and NS. + 2019-12-22 Bruno Haible setlocale-null: Add standalone include file. diff --git a/lib/xtime.h b/lib/xtime.h index 77f1c30faa..a442da5c0e 100644 --- a/lib/xtime.h +++ b/lib/xtime.h @@ -38,16 +38,18 @@ extern "C" { #endif /* Return an extended time value that contains S seconds and NS - nanoseconds. */ + nanoseconds. S and NS should be nonnegative; otherwise, integer + overflow can occur even if the result is in range. */ XTIME_INLINE xtime_t xtime_make (xtime_t s, long int ns) { - const long int giga = 1000 * 1000 * 1000; - s += ns / giga; - ns %= giga; return XTIME_PRECISION * s + ns; } +/* The following functions split an extended time value: + T = XTIME_PRECISION * xtime_sec (T) + xtime_nsec (T) + with 0 <= xtime_nsec (T) < XTIME_PRECISION. */ + /* Return the number of seconds in T, which must be nonnegative. */ XTIME_INLINE xtime_t xtime_nonnegative_sec (xtime_t t)