From 6648762916a0669e7f95b21cb2c39fb462114121 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 19 Aug 2011 14:14:18 +0000 Subject: [PATCH] * libc/time/mktime.c (validate_structure): Account for tm_mon possibly being given as negative. (mktime): Set tm_isdst=0 when !daylight. --- newlib/ChangeLog | 6 ++++++ newlib/libc/time/mktime.c | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 5d2053183..f600792e4 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,9 @@ +2011-08-19 Craig Howland + + * libc/time/mktime.c (validate_structure): Account for tm_mon possibly + being given as negative. + (mktime): Set tm_isdst=0 when !daylight. + 2011-08-01 Sebastian Huber * libc/include/sys/types.h: XML and RTEMS define diff --git a/newlib/libc/time/mktime.c b/newlib/libc/time/mktime.c index acd5d3aa0..93ca5c3a7 100644 --- a/newlib/libc/time/mktime.c +++ b/newlib/libc/time/mktime.c @@ -107,7 +107,7 @@ _DEFUN(validate_structure, (tim_p), } } - if (tim_p->tm_mon > 11) + if (tim_p->tm_mon < 0 || tim_p->tm_mon > 11) { res = div (tim_p->tm_mon, 12); tim_p->tm_year += res.quot; @@ -159,7 +159,7 @@ _DEFUN(mktime, (tim_p), { time_t tim = 0; long days = 0; - int year, isdst, tm_isdst; + int year, isdst=0; __tzinfo_type *tz = __gettzinfo (); /* validate structure */ @@ -204,15 +204,16 @@ _DEFUN(mktime, (tim_p), /* compute total seconds */ tim += (days * _SEC_IN_DAY); - /* Convert user positive into 1 */ - tm_isdst = tim_p->tm_isdst > 0 ? 1 : tim_p->tm_isdst; - isdst = tm_isdst; - TZ_LOCK; if (_daylight) { + int tm_isdst; int y = tim_p->tm_year + YEAR_BASE; + /* Convert user positive into 1 */ + tm_isdst = tim_p->tm_isdst > 0 ? 1 : tim_p->tm_isdst; + isdst = tm_isdst; + if (y == tz->__tzyear || __tzcalc_limits (y)) { /* calculate start of dst in dst local time and