bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mktime() hangs for dates before 1970


From: Ralf Wildenhues
Subject: Re: mktime() hangs for dates before 1970
Date: Sun, 30 Jan 2011 19:20:31 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

Hello Paul,

* Paul Eggert wrote on Sun, Jan 30, 2011 at 06:45:24PM CET:
> --- 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);

This doesn't make sense to me.  If long_int has the same width as int,
then the right hand side overflows thus invokes undefined behavior.
So I guess you're relying on the fact that compilers still will choose
some sane kind of behavior here by letting the result of the right hand
side be even, no matter what?  I wouldn't bet on that, compiler authors
can just elide a computation completely when they know it's undefined.

Cheers,
Ralf



reply via email to

[Prev in Thread] Current Thread [Next in Thread]