diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-09-09 16:56:29 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-09-09 16:56:29 +0000 |
commit | 41aba3d764a72e48fa5bb08969653582c38f319f (patch) | |
tree | feeee7701d8bbae975a0d26685572122b0e52525 | |
parent | eaa51b472caf30435e094b975308a5d45c13278a (diff) | |
download | glibc-41aba3d764a72e48fa5bb08969653582c38f319f.zip glibc-41aba3d764a72e48fa5bb08969653582c38f319f.tar.gz glibc-41aba3d764a72e48fa5bb08969653582c38f319f.tar.bz2 |
[BZ #2821]cvs/fedora-glibc-20060910T1832
* time/mktime.c (guess_time_tm): Fix overflow detection.
* time/Makefile (tests): Add bug-mktime1.
* time/bug-mktime1.c: New file.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | time/Makefile | 2 | ||||
-rw-r--r-- | time/bug-mktime1.c | 17 | ||||
-rw-r--r-- | time/mktime.c | 11 |
4 files changed, 29 insertions, 6 deletions
@@ -1,5 +1,10 @@ 2006-09-09 Ulrich Drepper <drepper@redhat.com> + [BZ #2821] + * time/mktime.c (guess_time_tm): Fix overflow detection. + * time/Makefile (tests): Add bug-mktime1. + * time/bug-mktime1.c: New file. + [BZ #3189, #3188] * misc/sys/mman.h (remap_file_pages): Make available for _GNU_SOURCE. (mremap): Likewise. diff --git a/time/Makefile b/time/Makefile index 734f0d5..d93b84b 100644 --- a/time/Makefile +++ b/time/Makefile @@ -35,7 +35,7 @@ distribute := datemsk tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \ - tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r + tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 include ../Rules diff --git a/time/bug-mktime1.c b/time/bug-mktime1.c new file mode 100644 index 0000000..e071273 --- /dev/null +++ b/time/bug-mktime1.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <time.h> + + +static int +do_test (void) +{ + struct tm t2 = { 0, 0, 0, 1, 1, 2050 - 1900, 1, 1, 1 }; + time_t tt2 = mktime (&t2); + printf ("%ld\n", (long int) tt2); + if (sizeof (time_t) == 4 && tt2 != -1) + return 1; + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/time/mktime.c b/time/mktime.c index 5a326d1..8f00c72 100644 --- a/time/mktime.c +++ b/time/mktime.c @@ -1,7 +1,7 @@ /* Convert a `struct tm' to a time_t value. - Copyright (C) 1993-1999, 2002-2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1993-1999, 2002-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. - Contributed by Paul Eggert (eggert@twinsun.com). + Contributed by Paul Eggert <eggert@twinsun.com>. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -216,10 +216,11 @@ guess_time_tm (long int year, long int yday, int hour, int min, int sec, /* Overflow occurred one way or another. Return the nearest result that is actually in range, except don't report a zero difference if the actual difference is nonzero, as that would cause a false - match. */ + match; and don't oscillate between two values, as that would + confuse the spring-forward gap detector. */ return (*t < TIME_T_MIDPOINT - ? TIME_T_MIN + (*t == TIME_T_MIN) - : TIME_T_MAX - (*t == TIME_T_MAX)); + ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) + : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); } /* Use CONVERT to convert *T to a broken down time in *TP. |