about summary refs log tree commit diff
path: root/time/mktime.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-09-09 16:56:29 +0000
committerUlrich Drepper <drepper@redhat.com>2006-09-09 16:56:29 +0000
commit41aba3d764a72e48fa5bb08969653582c38f319f (patch)
treefeeee7701d8bbae975a0d26685572122b0e52525 /time/mktime.c
parenteaa51b472caf30435e094b975308a5d45c13278a (diff)
downloadglibc-41aba3d764a72e48fa5bb08969653582c38f319f.tar.gz
glibc-41aba3d764a72e48fa5bb08969653582c38f319f.tar.xz
glibc-41aba3d764a72e48fa5bb08969653582c38f319f.zip
	* time/mktime.c (guess_time_tm): Fix overflow detection.
	* time/Makefile (tests): Add bug-mktime1.
	* time/bug-mktime1.c: New file.
Diffstat (limited to 'time/mktime.c')
-rw-r--r--time/mktime.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/time/mktime.c b/time/mktime.c
index 5a326d1e79..8f00c72e09 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.