[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mktime() hangs for dates before 1970
From: |
Paul Eggert |
Subject: |
Re: mktime() hangs for dates before 1970 |
Date: |
Sun, 30 Jan 2011 09:45:24 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 |
On 01/30/2011 01:17 AM, Ralf Wildenhues wrote:
> just to avoid surprises on new
> systems, why not use this:
>
> #elif defined(LLONG_MAX) && INT_MAX <= LLONG_MAX / 2
> typedef long long int long_int;
> #else
> # error "need a type that is wider than int"
> #endif
Thanks for mentioning this.
Although long_int width is already checked elsewhere,
the code can be reorganized to make the check clearer.
I pushed this:
---
ChangeLog | 8 ++++++++
lib/mktime.c | 11 +++++------
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c05c36f..2d57a0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-01-30 Paul Eggert <address@hidden>
+
+ mktime: clarify long_int width checking
+ * lib/mktime.c (long_int_is_wide_enough): Move this assertion to
+ the top level, to make it clearer that the assumption about
+ long_int width is being checked. See
+ <http://lists.gnu.org/archive/html/bug-gnulib/2011-01/msg00554.html>.
+
2011-01-30 Simon Josefsson <address@hidden>
ignore-value: Fix self-test.
diff --git a/lib/mktime.c b/lib/mktime.c
index 2486514..cba2b8b 100644
--- a/lib/mktime.c
+++ b/lib/mktime.c
@@ -64,12 +64,16 @@
# define mktime my_mktime
#endif /* DEBUG */
+/* Verify a requirement at compile-time (unlike assert, which is runtime). */
+#define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; }
+
/* A signed type that is at least one bit wider than int. */
#if INT_MAX <= LONG_MAX / 2
typedef long int long_int;
#else
typedef long long int long_int;
#endif
+verify (long_int_is_wide_enough, INT_MAX == INT_MAX * (long_int) 2 / 2);
/* Shift A right by B bits portably, by dividing A by 2**B and
truncating towards minus infinity. A and B should be free of side
@@ -123,9 +127,6 @@ typedef long long int long_int;
#endif
#define TIME_T_MIDPOINT (SHR (TIME_T_MIN + TIME_T_MAX, 1) + 1)
-/* Verify a requirement at compile-time (unlike assert, which is runtime). */
-#define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; }
-
verify (time_t_is_integer, TYPE_IS_INTEGER (time_t));
verify (twos_complement_arithmetic,
(TYPE_TWOS_COMPLEMENT (int)
@@ -196,8 +197,6 @@ ydhms_diff (long_int year1, long_int yday1, int hour1, int
min1, int sec1,
int year0, int yday0, int hour0, int min0, int sec0)
{
verify (C99_integer_division, -1 / 2 == 0);
- verify (long_int_year_and_yday_are_wide_enough,
- INT_MAX == INT_MAX * (long_int) 2 / 2);
/* Compute intervening leap days correctly even if year is negative.
Take care to avoid integer overflow here. */
@@ -733,6 +732,6 @@ main (int argc, char **argv)
/*
Local Variables:
-compile-command: "gcc -DDEBUG -Wall -W -O2 -g mktime.c -o mktime"
+compile-command: "gcc -DDEBUG -I. -Wall -W -O2 -g mktime.c -o mktime"
End:
*/
--
1.7.3
- mktime() hangs for dates before 1970, Benjamin Lindner, 2011/01/27
- Re: mktime() hangs for dates before 1970, Paul Eggert, 2011/01/27
- Re: mktime() hangs for dates before 1970, Benjamin Lindner, 2011/01/28
- Re: mktime() hangs for dates before 1970, Ralf Wildenhues, 2011/01/30
- Re: mktime() hangs for dates before 1970,
Paul Eggert <=
- Re: mktime() hangs for dates before 1970, Ralf Wildenhues, 2011/01/30
- Re: mktime() hangs for dates before 1970, Paul Eggert, 2011/01/30
- Re: mktime() hangs for dates before 1970, Ralf Wildenhues, 2011/01/30