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.
+2019-12-22 Bruno Haible <bruno@clisp.org>
+
+ 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 <bruno@clisp.org>
setlocale-null: Add standalone include file.
#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)