kern/128714: gmtime infinty loop
Giorgos Keramidas
keramida at freebsd.org
Sun Nov 9 22:30:08 PST 2008
The following reply was made to PR kern/128714; it has been noted by GNATS.
From: Giorgos Keramidas <keramida at freebsd.org>
To: Vladimir Timfeev <vovkasm at gmail.com>
Cc: freebsd-gnats-submit at freebsd.org
Subject: Re: kern/128714: gmtime infinty loop
Date: Mon, 10 Nov 2008 08:21:32 +0200
On Sun, 9 Nov 2008 01:56:54 GMT, Vladimir Timfeev <vovkasm at gmail.com> wrote:
> On amd64 platforms (tested with 6.2 and 7.0).
> gmtime from libc doesn't returns to program if called with
> arg < -33884019326476800
> May be we should return NULL?
> #include <time.h>
> #include <stdio.h>
>
> void test(time_t t) {
> struct tm *date;
> printf("try %ld\n",t);
> date = gmtime(&t);
> printf(" ok\n");
> }
>
> int main(void) {
> time_t time_ok = -33884019326476800LL;
> time_t time_err = -33884019326476801LL;
> test(time_ok);
> test(time_err);
> return 0;
> }
GCC warns about overflow when this is compiled with WARNS=6:
foo.c:12: warning: overflow in implicit constant conversion
foo.c:13: warning: overflow in implicit constant conversion
Maybe that's part of the problem. On i386 it seems to work FWIW, but it
does print bogus results (because of the implicit truncation that
happens when a huge negative number is assigned to time_t -- which is
equivalent to int32_t on i386):
$ ./foo
try -126116352
ok # Sun Jan 2 07:40:48 1966
try -126116353
ok # Sun Jan 2 07:40:47 1966
More information about the freebsd-bugs
mailing list