1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2026-03-21 08:15:46 +00:00

Minor library fixes for signed integer overflow.

* localtime.c (localsub, time2sub): Don't assume that signed
integer overflow wraps around.
This commit is contained in:
Paul Eggert
2014-08-19 12:51:10 -07:00
parent 13a277175c
commit 1f5348d829

View File

@ -1298,15 +1298,15 @@ localsub(const time_t *const timep, const int_fast32_t offset,
return NULL; /* "cannot happen" */
result = localsub(&newt, offset, tmp);
if (result == tmp) {
register time_t newy;
register int_fast64_t newy;
newy = tmp->tm_year;
if (t < sp->ats[0])
newy -= years;
else newy += years;
tmp->tm_year = newy;
if (tmp->tm_year != newy)
if (! (INT_MIN <= newy && newy <= INT_MAX))
return NULL;
tmp->tm_year = newy;
}
return result;
}
@ -1762,9 +1762,9 @@ time2sub(struct tm *const tmp,
}
if (increment_overflow32(&y, -TM_YEAR_BASE))
return WRONG;
yourtm.tm_year = y;
if (yourtm.tm_year != y)
if (! (INT_MIN <= y && y <= INT_MAX))
return WRONG;
yourtm.tm_year = y;
if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
saved_seconds = 0;
else if (y + TM_YEAR_BASE < EPOCH_YEAR) {