]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* time/mktime.c (__mktime_internal): If SEC_REQUESTED != SEC,
authorRoland McGrath <roland@gnu.org>
Thu, 2 Dec 2004 22:16:35 +0000 (22:16 +0000)
committerRoland McGrath <roland@gnu.org>
Thu, 2 Dec 2004 22:16:35 +0000 (22:16 +0000)
convert T2, not T.
* time/Makefile (tests): Add tst-mktime3.
* time/tst-mktime3.c: New test.

2004-12-01  Jakub Jelinek  <jakub@redhat.com>

ChangeLog
time/Makefile
time/mktime.c
time/tst-mktime3.c [new file with mode: 0644]

index f0434213bcc05e1cb755d0f61ecef829fa3808c1..b65a43f48e16c6413e2bc64714a7e698b003c466 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-12-01  Jakub Jelinek  <jakub@redhat.com>
+
+       * time/mktime.c (__mktime_internal): If SEC_REQUESTED != SEC,
+       convert T2, not T.
+       * time/Makefile (tests): Add tst-mktime3.
+       * time/tst-mktime3.c: New test.
+
 2004-12-01  Jakub Jelinek  <jakub@redhat.com>
 
        * stdlib/stdlib.h (realpath): Remove nonnull attribute.
index cb6ce4413df68871b691f0c690fe51d386fddbe3..7acc964fdc24d0000e0ac7fe16b9c47d31216501 100644 (file)
@@ -34,7 +34,8 @@ aux :=            era alt_digit lc-time-cleanup
 distribute := datemsk
 
 tests  := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
-          tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime
+          tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
+          tst-mktime3
 
 include ../Rules
 
index 280f5f47d518d016980e11eb6c65ebaf6ffc2986..c6ae56ee6024de3c7c72820029606ebe1624466a 100644 (file)
@@ -463,8 +463,9 @@ __mktime_internal (struct tm *tp,
       t2 = t1 + sec_adjustment;
       if (((t1 < t) != (sec_requested < 0))
          | ((t2 < t1) != (sec_adjustment < 0))
-         | ! (*convert) (&t, &tm))
+         | ! (*convert) (&t2, &tm))
        return -1;
+      t = t2;
     }
 
   *tp = tm;
diff --git a/time/tst-mktime3.c b/time/tst-mktime3.c
new file mode 100644 (file)
index 0000000..60d0e0b
--- /dev/null
@@ -0,0 +1,50 @@
+/* Test program for mktime bugs with out-of-range tm_sec values.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+struct tm tests[] =
+{
+  { .tm_sec = -1, .tm_mday = 1, .tm_year = 104 },
+  { .tm_sec = 65, .tm_min = 59, .tm_hour = 23, .tm_mday = 31,
+    .tm_mon = 11, .tm_year = 101 }
+};
+struct tm expected[] =
+{
+  { .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31,
+    .tm_mon = 11, .tm_year = 103, .tm_wday = 3, .tm_yday = 364 },
+  { .tm_sec = 5, .tm_mday = 1, .tm_year = 102, .tm_wday = 2 }
+};
+
+int
+main (void)
+{
+  setenv ("TZ", "UTC", 1);
+  int i;
+  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+    {
+      if (mktime (&tests[i]) < 0)
+       {
+         printf ("mktime %d failed\n", i);
+         return 1;
+       }
+#define CHECK(name) \
+      if (tests[i].name != expected[i].name)                   \
+       {                                                       \
+         printf ("test %d " #name " got %d expected %d\n",     \
+                 i, tests[i].name, expected[i].name);          \
+         return 1;                                             \
+       }
+      CHECK (tm_sec)
+      CHECK (tm_min)
+      CHECK (tm_hour)
+      CHECK (tm_mday)
+      CHECK (tm_mon)
+      CHECK (tm_year)
+      CHECK (tm_wday)
+      CHECK (tm_yday)
+      CHECK (tm_isdst)
+    }
+  return 0;
+}