diff options
author | Jim Meyering <jim@meyering.net> | 1999-03-28 20:58:51 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-03-28 20:58:51 +0000 |
commit | 7549c10f354233f57487fe4025251d0c11010fab (patch) | |
tree | 4b34ebb995fd6775c96bed4cd3effa1e2c27cc7b /lib/getdate.y | |
parent | 45eb6519020d2e65c41790fea829aa89c93069a1 (diff) | |
download | coreutils-7549c10f354233f57487fe4025251d0c11010fab.tar.xz |
(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.
Diffstat (limited to 'lib/getdate.y')
-rw-r--r-- | lib/getdate.y | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/getdate.y b/lib/getdate.y index 9f8f95f1c..0407f153f 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; |