+2011-01-29 Eric Blake <eblake@redhat.com>
+
+ mktime: avoid infinite loop
+ * m4/mktime.m4 (AC_FUNC_MKTIME): Avoid overflow on possibly-signed
+ type; behavior is still undefined but portable to all known targets.
+ Reported by Rich Felker.
+
2011-01-29 Simon Josefsson <simon@josefsson.org>
rename, unlink, same-inode: Relicense.
-# serial 17
+# serial 18
dnl Copyright (C) 2002-2003, 2005-2007, 2009-2011 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
int result = 0;
time_t t, delta;
int i, j;
+ int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1;
+ int time_t_signed = ! ((time_t) 0 < (time_t) -1);
/* This test makes some buggy mktime implementations loop.
Give up after 60 seconds; a mktime slower than that
isn't worth using anyway. */
alarm (60);
- 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;
+ time_t_max = (! time_t_signed
+ ? (time_t) -1
+ : ~ (~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)));
+ time_t_min = (! time_t_signed
+ ? (time_t) 0
+ : time_t_signed_magnitude
+ ? ~ (time_t) 0
+ : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1));
delta = time_t_max / 997; /* a suitable prime number */
for (i = 0; i < N_STRINGS; i++)