From dc062ad089529e692add3aee0564a73a0812f212 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 28 Mar 1999 20:58:51 +0000 Subject: [PATCH] (get_date): Reuse tm_isdst of first localtime call; this is an improvement on a bug fix suggested by martin@dresden.nacamar.de. Do not assume that localtime and gmtime return non-null. From Paul Eggert. --- lib/getdate.y | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index 9f8f95f1c2..0407f153f1 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -906,12 +906,15 @@ get_date (const char *p, const time_t *now) yyInput = p; Start = now ? *now : time ((time_t *) NULL); tmp = localtime (&Start); + if (!tmp) + return -1; yyYear = tmp->tm_year + TM_YEAR_ORIGIN; yyMonth = tmp->tm_mon + 1; yyDay = tmp->tm_mday; yyHour = tmp->tm_hour; yyMinutes = tmp->tm_min; yySeconds = tmp->tm_sec; + tm.tm_isdst = tmp->tm_isdst; yyMeridian = MER24; yyRelSeconds = 0; yyRelMinutes = 0; @@ -947,7 +950,6 @@ get_date (const char *p, const time_t *now) tm.tm_hour += yyRelHour; tm.tm_min += yyRelMinutes; tm.tm_sec += yyRelSeconds; - tm.tm_isdst = -1; tm0 = tm; Start = mktime (&tm); @@ -994,7 +996,11 @@ get_date (const char *p, const time_t *now) if (yyHaveZone) { - long delta = yyTimezone * 60L + difftm (&tm, gmtime (&Start)); + long delta; + struct tm *gmt = gmtime (&Start); + if (!gmt) + return -1; + delta = yyTimezone * 60L + difftm (&tm, gmt); if ((Start + delta < Start) != (delta < 0)) return -1; /* time_t overflow */ Start += delta; -- 2.30.2