summaryrefslogtreecommitdiff
path: root/lib/time_rz.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-03-26 19:23:33 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2018-03-27 13:23:16 -0700
commit96caee5e9a16b172611c6ead9df0ab39cb7acfa6 (patch)
treef8a99595f3b73c50bfa8d1444a5b29f0cb4d4d91 /lib/time_rz.c
parent8326a2e524119decf07d07a072a6c15bebefef0e (diff)
downloadgnulib-96caee5e9a16b172611c6ead9df0ab39cb7acfa6.tar.gz
time_rz: work around Mac OS X 10.6 infloop
* doc/posix-functions/localtime.texi: * doc/posix-functions/localtime_r.texi: Mention the bug. * lib/time_rz.c (localtime_rz): Work around the bug. It’d be better to fix localtime and localtime_r instead, but that would be more work and is not needed to fix the Emacs problem. * m4/time_rz.m4 (gl_TIME_RZ): Detect the bug.
Diffstat (limited to 'lib/time_rz.c')
-rw-r--r--lib/time_rz.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/time_rz.c b/lib/time_rz.c
index 4682beb573..f9262c1720 100644
--- a/lib/time_rz.c
+++ b/lib/time_rz.c
@@ -286,6 +286,21 @@ revert_tz (timezone_t tz)
struct tm *
localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
{
+#ifdef HAVE_LOCALTIME_INFLOOP_BUG
+ /* The -67768038400665599 comes from:
+ https://lists.gnu.org/r/bug-gnulib/2017-07/msg00142.html
+ On affected platforms the greatest POSIX-compatible time_t value
+ that could return nonnull is 67768036191766798 (when
+ TZ="XXX24:59:59" it resolves to the year 2**31 - 1 + 1900, on
+ 12-31 at 23:59:59), so test for that too while we're in the
+ neighborhood. */
+ if (! (-67768038400665599 <= *t && *t <= 67768036191766798))
+ {
+ errno = EOVERFLOW;
+ return NULL;
+ }
+#endif
+
if (!tz)
return gmtime_r (t, tm);
else