]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/autoconf/functions.m4 (AC_FUNC_MKTIME):
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 22 Dec 2006 08:42:17 +0000 (08:42 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 22 Dec 2006 08:42:17 +0000 (08:42 +0000)
Include <limits.h>, and use its INT_MAX to rewrite the
j loop so that it does not overflow 'int'.  Problem reported by
Ralf Wildenhues in
<http://lists.gnu.org/archive/html/bug-gnulib/2006-12/msg00084.html>.
Play it safe by shifting left by 1 rather than multiplying by 2,
as GCC is less likely to optimize this away when the value
is signed (when it assumes overflow leads to undefined behavior).
Also, don't assume time_t uses two's complement.

ChangeLog
lib/autoconf/functions.m4

index 50086131744a19026faae31d051bc46833b64a14..94cfae32ed2f5a8ca3e93e6e63e0c9d8a4bbbf83 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-12-22  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * lib/autoconf/functions.m4 (AC_FUNC_MKTIME):
+       Include <limits.h>, and use its INT_MAX to rewrite the
+       j loop so that it does not overflow 'int'.  Problem reported by
+       Ralf Wildenhues in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2006-12/msg00084.html>.
+       Play it safe by shifting left by 1 rather than multiplying by 2,
+       as GCC is less likely to optimize this away when the value
+       is signed (when it assumes overflow leads to undefined behavior).
+       Also, don't assume time_t uses two's complement.
+
 2006-12-20  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * tests/torture.at (Substitute a 2000-byte string): Avoid using
index 185376e9f992dc16960c063859ada4d57d8e87d4..a34c9f0e179c31a0e69d0e1e59dd278f6d70d3d3 100644 (file)
@@ -984,6 +984,7 @@ AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
 # endif
 #endif
 
+#include <limits.h>
 #include <stdlib.h>
 
 #ifdef HAVE_UNISTD_H
@@ -1132,12 +1133,15 @@ main ()
      isn't worth using anyway.  */
   alarm (60);
 
-  for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
-    continue;
-  time_t_max--;
-  if ((time_t) -1 < 0)
-    for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
-      continue;
+  for (;;)
+    {
+      t = (time_t_max << 1) + 1;
+      if (t <= time_t_max)
+       break;
+      time_t_max = t;
+    }
+  time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
+
   delta = time_t_max / 997; /* a suitable prime number */
   for (i = 0; i < N_STRINGS; i++)
     {
@@ -1152,10 +1156,12 @@ main ()
             && mktime_test ((time_t) (60 * 60 * 24))))
        return 1;
 
-      for (j = 1; 0 < j; j *= 2)
+      for (j = 1; ; j <<= 1)
        if (! bigtime_test (j))
          return 1;
-      if (! bigtime_test (j - 1))
+       else if (INT_MAX / 2 < j)
+         break;
+      if (! bigtime_test (INT_MAX))
        return 1;
     }
   return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());