bug-gnulib
[Top][All Lists]
Advanced

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

Re: posixtm: doesn't like -1 for 32-bit time_t's?


From: Simon Josefsson
Subject: Re: posixtm: doesn't like -1 for 32-bit time_t's?
Date: Thu, 21 Jun 2012 04:54:15 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/23.3 (gnu/linux)

Paul Eggert <address@hidden> writes:

> On 06/20/2012 10:43 AM, Simon Josefsson wrote:
>
>> Has this test worked on any 32-bit time_t machines?
>
> Sure, lots.
>
>> 190112132045.51 return value mismatch: got 0, expected 1
>> 
>> and that time corresponds to (time_t) -1.  Any ideas?
>
> That time is corresponds to -2147483649
> (i.e., -2**31 - 1), not to -1.

Right.

> On a host with 32-bit signed time_t, that test
> case should be filtered out by this code:
>
>       if (! (TYPE_MINIMUM (time_t) <= T[i].t_expected
>              && T[i].t_expected <= TYPE_MAXIMUM (time_t)))
>         {
>           printf ("skipping %s: result is out of range of your time_t\n",
>                   T[i].in);
>           continue;
>         }
>
> because TYPE_MINIMUM (time_t) should evaluate to
> -2**31, which is greater than -2**31 - 1.
>
> Conversely, that filter did *not* work for
> 190112132045.52 (i.e., -2**31), as it complained
> that the result is out of your time_t range, but
> it is in range.
>
> Can you debug the program to see why the filter isn't
> working?  Perhaps disassemble it?  I wouldn't be surprised
> if it were a compiler bug.

The reason was that the int64_t in T[i].t_expected initialized via this
line:

    { "190112132045.51", 13, 1,  -2147483649}, /* Fri Dec 13 20:45:51 1901 */

got the value 2147483647.  Reproduce like this:

address@hidden:~# cat foo.c
#include <stdint.h>
#include <stdio.h>

int
main (void)
{
  int64_t i = -2147483649;

  printf ("i %lld\n", i);

  return 0;
}
address@hidden:~# gcc -o foo foo.c
foo.c: In function ‘main’:
foo.c:7:3: warning: this decimal constant is unsigned only in ISO C90 [enabled 
by default]
address@hidden:~# ./foo
i 2147483647
address@hidden:~# 

Interestingly, the following works fine and yields no warning.

address@hidden:~# cat foo.c
#include <stdint.h>
#include <stdio.h>

int
main (void)
{
  int64_t i = -62167219200;

  printf ("i %lld\n", i);

  return 0;
}
address@hidden:~# gcc -o foo foo.c
address@hidden:~# ./foo
i -62167219200
address@hidden:~# 

Experimenting, it seems values between -2^31-1 and -2^32-1 inclusive
trigger this while -2^32 leads to no warning.

Changing the line into

    { "190112132045.51", 13, 1,  -2147483649LL}, /* Fri Dec 13 20:45:51 1901 */

makes the self-test work.

/Simon



reply via email to

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