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. --- libc/time/Makefile 14 Oct 2005 15:16:17 -0000 1.109 +++ libc/time/Makefile 9 Sep 2006 16:54:49 -0000 1.110 @@ -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 --- libc/time/bug-mktime1.c 1 Jan 1970 00:00:00 -0000 +++ libc/time/bug-mktime1.c 9 Sep 2006 16:54:23 -0000 1.1 @@ -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" --- libc/time/mktime.c 8 Sep 2005 08:09:07 -0000 1.66 +++ libc/time/mktime.c 9 Sep 2006 16:56:18 -0000 1.67 @@ -216,10 +216,11 @@ guess_time_tm (long int year, long int y /* 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.