summaryrefslogtreecommitdiffstats
path: root/newlib/libc/time/mktime.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/time/mktime.c')
-rw-r--r--newlib/libc/time/mktime.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/newlib/libc/time/mktime.c b/newlib/libc/time/mktime.c
index 8cd9564a9..0ee055cd0 100644
--- a/newlib/libc/time/mktime.c
+++ b/newlib/libc/time/mktime.c
@@ -211,9 +211,12 @@ mktime (tim_p)
{
/* calculate start of dst in dst local time and
start of std in both std local time and dst local time */
- time_t startdst_dst = tz->__tzrule[0].change - tz->__tzrule[1].offset;
- time_t startstd_dst = tz->__tzrule[1].change - tz->__tzrule[1].offset;
- time_t startstd_std = tz->__tzrule[1].change - tz->__tzrule[0].offset;
+ time_t startdst_dst = tz->__tzrule[0].change
+ - (time_t) tz->__tzrule[1].offset;
+ time_t startstd_dst = tz->__tzrule[1].change
+ - (time_t) tz->__tzrule[1].offset;
+ time_t startstd_std = tz->__tzrule[1].change
+ - (time_t) tz->__tzrule[0].offset;
/* if the time is in the overlap between dst and std local times */
if (tim >= startstd_std && tim < startstd_dst)
; /* we let user decide or leave as -1 */
@@ -226,8 +229,12 @@ mktime (tim_p)
if ((isdst ^ tim_p->tm_isdst) == 1)
{
/* we either subtract or add the difference between
- time zone offsets, depending on which way the user got it wrong */
- int diff = tz->__tzrule[0].offset - tz->__tzrule[1].offset;
+ time zone offsets, depending on which way the user got it
+ wrong. The diff is typically one hour, or 3600 seconds,
+ and should fit in a 16-bit int, even though offset
+ is a long to accomodate 12 hours. */
+ int diff = (int) (tz->__tzrule[0].offset
+ - tz->__tzrule[1].offset);
if (!isdst)
diff = -diff;
tim_p->tm_sec += diff;
@@ -240,9 +247,9 @@ mktime (tim_p)
/* add appropriate offset to put time in gmt format */
if (isdst == 1)
- tim += tz->__tzrule[1].offset;
+ tim += (time_t) tz->__tzrule[1].offset;
else /* otherwise assume std time */
- tim += tz->__tzrule[0].offset;
+ tim += (time_t) tz->__tzrule[0].offset;
/* reset isdst flag to what we have calculated */
tim_p->tm_isdst = isdst;