* [PATCH] Fix mktime
@ 2002-04-13 2:59 Jakub Jelinek
2002-04-14 23:27 ` Ulrich Drepper
2002-04-17 5:22 ` Thorsten Kukuk
0 siblings, 2 replies; 5+ messages in thread
From: Jakub Jelinek @ 2002-04-13 2:59 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
Hi!
The PR libc/2738 fix was not entirely correct, since even tm with tm_year 69
is representable in certain timezones. This caused e.g. perl-Date-Calc tests
to fail. Below is a fix. Years before 69 surely cannot be represented, for
69 it computes the year and checks for overflow afterwards.
2002-04-13 Jakub Jelinek <jakub@redhat.com>
* time/mktime.c (__mktime_internal): If year is 69, don't bail out
early, but check whether it overflowed afterwards.
* time/tst-mktime.c (main): Add new tests.
--- libc/time/mktime.c.jj Sun Apr 7 17:52:27 2002
+++ libc/time/mktime.c Sat Apr 13 11:12:05 2002
@@ -259,8 +259,10 @@ __mktime_internal (struct tm *tp,
int sec_requested = sec;
- /* Only years after 1970 are defined. */
- if (year < 70)
+ /* Only years after 1970 are defined.
+ If year is 69, it might still be representable due to
+ timezone differnces. */
+ if (year < 69)
return -1;
#if LEAP_SECONDS_POSSIBLE
@@ -370,6 +372,14 @@ __mktime_internal (struct tm *tp,
return -1;
}
+ if (year == 69)
+ {
+ /* If year was 69, need to check whether the time was representable
+ or not. */
+ if (t < 0 || t > 2 * 24 * 60 * 60)
+ return -1;
+ }
+
*tp = tm;
return t;
}
--- libc/time/tst-mktime.c.jj Sat Apr 13 11:45:06 2002
+++ libc/time/tst-mktime.c Sat Apr 13 11:58:22 2002
@@ -5,7 +5,8 @@
int
main (void)
{
- struct tm time_str;
+ struct tm time_str, *tm;
+ time_t t;
char daybuf[20];
int result;
@@ -29,5 +30,38 @@ main (void)
result = strcmp (daybuf, "Wednesday") != 0;
}
+ setenv ("TZ", "EST", 1);
+#define EVENING69 1 * 60 * 60 + 2 * 60 + 29
+ t = EVENING69;
+ tm = localtime (&t);
+ if (tm == NULL)
+ {
+ (void) puts ("localtime returned NULL");
+ result = 1;
+ }
+ else
+ {
+ time_str = *tm;
+ t = mktime (&time_str);
+ if (t != EVENING69)
+ {
+ printf ("mktime returned %ld, expected %ld\n",
+ (long) t, EVENING69);
+ result = 1;
+ }
+ else
+ (void) puts ("Dec 31 1969 EST test passed");
+
+ setenv ("TZ", "CET", 1);
+ t = mktime (&time_str);
+ if (t != (time_t) -1)
+ {
+ printf ("mktime returned %ld, expected -1\n", (long) t);
+ result = 1;
+ }
+ else
+ (void) puts ("Dec 31 1969 CET test passed");
+ }
+
return result;
}
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix mktime
2002-04-13 2:59 [PATCH] Fix mktime Jakub Jelinek
@ 2002-04-14 23:27 ` Ulrich Drepper
2002-04-17 5:22 ` Thorsten Kukuk
1 sibling, 0 replies; 5+ messages in thread
From: Ulrich Drepper @ 2002-04-14 23:27 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
[-- Attachment #1: Type: text/plain, Size: 541 bytes --]
On Sat, 2002-04-13 at 02:59, Jakub Jelinek wrote:
> 2002-04-13 Jakub Jelinek <jakub@redhat.com>
>
> * time/mktime.c (__mktime_internal): If year is 69, don't bail out
> early, but check whether it overflowed afterwards.
> * time/tst-mktime.c (main): Add new tests.
I've applied the patch. Thanks,
--
---------------. ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Red Hat `--' drepper at redhat.com `------------------------
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 232 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix mktime
2002-04-13 2:59 [PATCH] Fix mktime Jakub Jelinek
2002-04-14 23:27 ` Ulrich Drepper
@ 2002-04-17 5:22 ` Thorsten Kukuk
2002-04-17 5:45 ` [PATCH] tst-mktime.c Jakub Jelinek
1 sibling, 1 reply; 5+ messages in thread
From: Thorsten Kukuk @ 2002-04-17 5:22 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
On Sat, Apr 13, Jakub Jelinek wrote:
> Hi!
>
> The PR libc/2738 fix was not entirely correct, since even tm with tm_year 69
> is representable in certain timezones. This caused e.g. perl-Date-Calc tests
> to fail. Below is a fix. Years before 69 surely cannot be represented, for
> 69 it computes the year and checks for overflow afterwards.
>
> 2002-04-13 Jakub Jelinek <jakub@redhat.com>
>
> * time/mktime.c (__mktime_internal): If year is 69, don't bail out
> early, but check whether it overflowed afterwards.
> * time/tst-mktime.c (main): Add new tests.
make check does not longer pass for me with this. Output of
tst-mktime.out is:
Wednesday
Dec 31 1969 EST test passed
mktime returned 3749, expected -1
Thorsten
--
Thorsten Kukuk http://www.suse.de/~kukuk/ kukuk@suse.de
SuSE Linux AG Deutschherrenstr. 15-19 D-90429 Nuernberg
--------------------------------------------------------------------
Key fingerprint = A368 676B 5E1B 3E46 CFCE 2D97 F8FD 4E23 56C6 FB4B
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] tst-mktime.c
2002-04-17 5:22 ` Thorsten Kukuk
@ 2002-04-17 5:45 ` Jakub Jelinek
2002-04-17 6:48 ` Thorsten Kukuk
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2002-04-17 5:45 UTC (permalink / raw)
To: Thorsten Kukuk; +Cc: Glibc hackers
On Wed, Apr 17, 2002 at 02:21:46PM +0200, Thorsten Kukuk wrote:
> On Sat, Apr 13, Jakub Jelinek wrote:
>
> > Hi!
> >
> > The PR libc/2738 fix was not entirely correct, since even tm with tm_year 69
> > is representable in certain timezones. This caused e.g. perl-Date-Calc tests
> > to fail. Below is a fix. Years before 69 surely cannot be represented, for
> > 69 it computes the year and checks for overflow afterwards.
> >
> > 2002-04-13 Jakub Jelinek <jakub@redhat.com>
> >
> > * time/mktime.c (__mktime_internal): If year is 69, don't bail out
> > early, but check whether it overflowed afterwards.
> > * time/tst-mktime.c (main): Add new tests.
>
> make check does not longer pass for me with this. Output of
> tst-mktime.out is:
>
> Wednesday
> Dec 31 1969 EST test passed
> mktime returned 3749, expected -1
Weird, I get
Wednesday
Dec 31 1969 EST test passed
Dec 31 1969 CET test passed
on all arches I've bootstrapped it (i386,i686,ia64,alpha,alphaev6).
Looks like tst-mktime cannot find the CET zone file on your box.
Does the following work for you?
Passes for me with current glibc, fails with:
Wednesday
mktime returned -1, expected 3749
Dec 31 1969 CET test passed
with glibc before my mktime patch (expected).
2002-04-17 Jakub Jelinek <jakub@redhat.com>
* time/tst-mktime.c: Include <stdlib.h>.
Use %d, not %ld format for EVENING69.
Include offsets in TZ environment variable.
--- libc/time/tst-mktime.c.jj Wed Apr 17 14:34:34 2002
+++ libc/time/tst-mktime.c Wed Apr 17 14:48:32 2002
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
@@ -30,7 +31,7 @@ main (void)
result = strcmp (daybuf, "Wednesday") != 0;
}
- setenv ("TZ", "EST", 1);
+ setenv ("TZ", "EST+5", 1);
#define EVENING69 1 * 60 * 60 + 2 * 60 + 29
t = EVENING69;
tm = localtime (&t);
@@ -45,14 +46,14 @@ main (void)
t = mktime (&time_str);
if (t != EVENING69)
{
- printf ("mktime returned %ld, expected %ld\n",
+ printf ("mktime returned %ld, expected %d\n",
(long) t, EVENING69);
result = 1;
}
else
(void) puts ("Dec 31 1969 EST test passed");
- setenv ("TZ", "CET", 1);
+ setenv ("TZ", "CET-1", 1);
t = mktime (&time_str);
if (t != (time_t) -1)
{
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tst-mktime.c
2002-04-17 5:45 ` [PATCH] tst-mktime.c Jakub Jelinek
@ 2002-04-17 6:48 ` Thorsten Kukuk
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Kukuk @ 2002-04-17 6:48 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
On Wed, Apr 17, Jakub Jelinek wrote:
> > make check does not longer pass for me with this. Output of
> > tst-mktime.out is:
> >
> > Wednesday
> > Dec 31 1969 EST test passed
> > mktime returned 3749, expected -1
>
> Weird, I get
> Wednesday
> Dec 31 1969 EST test passed
> Dec 31 1969 CET test passed
>
> on all arches I've bootstrapped it (i386,i686,ia64,alpha,alphaev6).
> Looks like tst-mktime cannot find the CET zone file on your box.
Arg, ok, this was it. On this machine was really no timezone data
installed :(
Thanks for the hint,
Thorsten
--
Thorsten Kukuk http://www.suse.de/~kukuk/ kukuk@suse.de
SuSE Linux AG Deutschherrenstr. 15-19 D-90429 Nuernberg
--------------------------------------------------------------------
Key fingerprint = A368 676B 5E1B 3E46 CFCE 2D97 F8FD 4E23 56C6 FB4B
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-04-17 13:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-13 2:59 [PATCH] Fix mktime Jakub Jelinek
2002-04-14 23:27 ` Ulrich Drepper
2002-04-17 5:22 ` Thorsten Kukuk
2002-04-17 5:45 ` [PATCH] tst-mktime.c Jakub Jelinek
2002-04-17 6:48 ` Thorsten Kukuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).