1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2025-11-22 10:10:54 +00:00

Avoid integer overflow in mktime

* localtime.c (time2sub), NEWS: Avoid signed arithmetic overflow.
(Problem reported by Jörg Richter.)
This commit is contained in:
Paul Eggert
2015-03-10 09:37:50 -07:00
parent be32412b10
commit 4c8309661d
2 changed files with 9 additions and 11 deletions

View File

@ -1783,10 +1783,10 @@ time2sub(struct tm *const tmp,
register int dir;
register int i, j;
register int saved_seconds;
register int_fast32_t li;
register int_fast32_t li;
register time_t lo;
register time_t hi;
int_fast32_t y;
int_fast32_t y;
time_t newt;
time_t t;
struct tm yourtm, mytm;
@ -1861,15 +1861,8 @@ time2sub(struct tm *const tmp,
/*
** Do a binary search (this works whatever time_t's type is).
*/
if (!TYPE_SIGNED(time_t)) {
lo = 0;
hi = lo - 1;
} else {
lo = 1;
for (i = 0; i < (int) TYPE_BIT(time_t) - 1; ++i)
lo *= 2;
hi = -(lo + 1);
}
lo = time_t_min;
hi = time_t_max;
for ( ; ; ) {
t = lo / 2 + hi / 2;
if (t < lo)