From 51075b0f5c8bff2efd78c4f44f70270152991371 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 11 Sep 2014 00:11:37 -0700 Subject: [PROPOSED PATCH 4/4] Minor localtime fixups. * localtime.c (localsub): Tune slightly. Don't set tzname unless successful. (gmtime_r, offtime, timeoff): Simplify. * NEWS: Document the tzname change. --- NEWS | 2 ++ localtime.c | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 0e58e97..a2a7355 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ Unreleased, experimental changes on platforms not defining TM_ZONE, fixing a 2014g regression. (Thanks to Tim Parenti for reporting the problem.) + The tz library no longer sets tzname if localtime or mktime fails. + zdump -c no longer mishandles transitions near year boundaries. (Thanks to Tim Parenti for reporting the problem.) diff --git a/localtime.c b/localtime.c index 354d0d7..62743e2 100644 --- a/localtime.c +++ b/localtime.c @@ -1333,16 +1333,16 @@ localsub(struct state const *sp, time_t const *timep, int_fast32_t offset, newt > sp->ats[sp->timecnt - 1]) return NULL; /* "cannot happen" */ result = localsub(sp, &newt, offset, tmp); - if (result == tmp) { + if (result) { register int_fast64_t newy; - newy = tmp->tm_year; + newy = result->tm_year; if (t < sp->ats[0]) newy -= years; else newy += years; if (! (INT_MIN <= newy && newy <= INT_MAX)) return NULL; - tmp->tm_year = newy; + result->tm_year = newy; } return result; } @@ -1369,12 +1369,14 @@ localsub(struct state const *sp, time_t const *timep, int_fast32_t offset, ** timesub(&t, 0L, sp, tmp); */ result = timesub(&t, ttisp->tt_gmtoff, sp, tmp); - tmp->tm_isdst = ttisp->tt_isdst; - if (result && offset) - tzname[tmp->tm_isdst] = (char *) &sp->chars[ttisp->tt_abbrind]; + if (result) { + result->tm_isdst = ttisp->tt_isdst; + if (offset) + tzname[result->tm_isdst] = (char *) &sp->chars[ttisp->tt_abbrind]; #ifdef TM_ZONE - tmp->TM_ZONE = (char *) &sp->chars[ttisp->tt_abbrind]; + result->TM_ZONE = (char *) &sp->chars[ttisp->tt_abbrind]; #endif /* defined TM_ZONE */ + } return result; } @@ -1452,8 +1454,7 @@ struct tm * gmtime_r(const time_t *const timep, struct tm *tmp) { gmtcheck(); - tmp = gmtsub(gmtptr, timep, 0, tmp); - return tmp; + return gmtsub(gmtptr, timep, 0, tmp); } #ifdef STD_INSPIRED @@ -1461,10 +1462,8 @@ gmtime_r(const time_t *const timep, struct tm *tmp) struct tm * offtime(const time_t *const timep, const long offset) { - struct tm *tmp; gmtcheck(); - tmp = gmtsub(gmtptr, timep, offset, &tm); - return tmp; + return gmtsub(gmtptr, timep, offset, &tm); } #endif /* defined STD_INSPIRED */ @@ -2081,12 +2080,10 @@ timegm(struct tm *const tmp) time_t timeoff(struct tm *const tmp, const long offset) { - time_t t; if (tmp) tmp->tm_isdst = 0; gmtcheck(); - t = time1(tmp, gmtsub, gmtptr, offset); - return t; + return time1(tmp, gmtsub, gmtptr, offset); } #endif /* defined STD_INSPIRED */ -- 1.9.3