* lib/gettime-res.c (gettime_res): Fix bug when hz * tv_sec overflows.
With 64-bit ‘long’ and nanosecond resolution the bug can occur
starting in the year 2262, with probability about 2e-9.
With 32-bit ‘long’ the bug can occur now, with same probability.
The probability goes up on hosts with worse timestamp resolution.
2022-02-26 Paul Eggert <eggert@cs.ucla.edu>
+ gettime-res: fix unlikely overflow bug
+ * lib/gettime-res.c (gettime_res): Fix bug when hz * tv_sec overflows.
+ With 64-bit ‘long’ and nanosecond resolution the bug can occur
+ starting in the year 2262, with probability about 2e-9.
+ With 32-bit ‘long’ the bug can occur now, with same probability.
+ The probability goes up on hosts with worse timestamp resolution.
+
Document clang -fsanitize=undefined glitch
* doc/gnulib-intro.texi (Unsupported Platforms):
Document incompatibility of ‘clang -fsanitize=undefined’
for (int i = 0; 1 < r && i < 32; i++)
{
struct timespec now = current_timespec ();
- r = gcd (r, now.tv_nsec ? now.tv_nsec : hz * now.tv_sec);
+ r = gcd (r, now.tv_nsec ? now.tv_nsec : hz);
}
return r;