]> Savannah Git Hosting - gnulib.git/commitdiff
time_rz: fix issues with mktime_z failures
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 16 Aug 2020 18:54:44 +0000 (11:54 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 16 Aug 2020 18:56:10 +0000 (11:56 -0700)
* lib/time_rz.c (mktime_z): Do not update *TM if revert_tz fails.
Use a cheaper tm_yday test for failed mktime.

ChangeLog
lib/time_rz.c

index 0810c1106ce676d760950112de940ae3bfac67d7..2e4651751ba83d136e9ae2c172f57481c2df919d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+       time_rz: fix issues with mktime_z failures
+       * lib/time_rz.c (mktime_z): Do not update *TM if revert_tz fails.
+       Use a cheaper tm_yday test for failed mktime.
+
 2020-08-16  Bruno Haible  <bruno@clisp.org>
 
        intprops test: Strengthen on clang.
index 0a8aac999f989570c3aa4d2a9372180eac91ec58..8ed3c4443370cd4f763b3288ff052bf7f59054f9 100644 (file)
@@ -327,17 +327,25 @@ mktime_z (timezone_t tz, struct tm *tm)
       timezone_t old_tz = set_tz (tz);
       if (old_tz)
         {
-          time_t t = mktime (tm);
-#if HAVE_TM_ZONE || HAVE_TZNAME
-          time_t badtime = -1;
           struct tm tm_1;
-          if ((t != badtime
-               || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
-              && !save_abbr (tz, tm))
-            t = badtime;
+          tm_1.tm_sec = tm->tm_sec;
+          tm_1.tm_min = tm->tm_min;
+          tm_1.tm_hour = tm->tm_hour;
+          tm_1.tm_mday = tm->tm_mday;
+          tm_1.tm_mon = tm->tm_mon;
+          tm_1.tm_year = tm->tm_year;
+          tm_1.tm_yday = -1;
+          tm_1.tm_isdst = tm->tm_isdst;
+          time_t t = mktime (&tm_1);
+          bool ok = 0 <= tm_1.tm_yday;
+#if HAVE_TM_ZONE || HAVE_TZNAME
+          ok = ok && save_abbr (tz, &tm_1);
 #endif
-          if (revert_tz (old_tz))
-            return t;
+          if (revert_tz (old_tz) && ok)
+            {
+              *tm = tm_1;
+              return t;
+            }
         }
       return -1;
     }