Mercurial > hg > octave-nkf > gnulib-hg
changeset 1761:14b8e8de40c8
(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.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sun, 28 Mar 1999 20:58:51 +0000 |
parents | b9e8f52f49b4 |
children | 9e049b469983 |
files | lib/getdate.y |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/getdate.y +++ b/lib/getdate.y @@ -906,12 +906,15 @@ 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 @@ 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 @@ 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;