summaryrefslogtreecommitdiff
path: root/lib/getdate.y
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-03-28 20:58:51 +0000
committerJim Meyering <jim@meyering.net>1999-03-28 20:58:51 +0000
commit7549c10f354233f57487fe4025251d0c11010fab (patch)
tree4b34ebb995fd6775c96bed4cd3effa1e2c27cc7b /lib/getdate.y
parent45eb6519020d2e65c41790fea829aa89c93069a1 (diff)
downloadcoreutils-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.y10
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;