>From e994d4b36b8fc37844fe39cea0f30501864e2db7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 22 Dec 2019 12:38:22 -0800 Subject: [PATCH 1/2] gethrxtime: remove incorrect overflow detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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!address@hidden, 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. --- ChangeLog | 10 ++++++++++ lib/xtime.h | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5dedb14d..25c8c4755 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!address@hidden, 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 77f1c30fa..a442da5c0 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) -- 2.17.1