(tmcomp): Don't mess up when atmp->tm_year - btmp->tm_year overflows. This can happen when mktime is invoked on a struct tm with tm_year equal to INT_MIN. --- localtime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/localtime.c b/localtime.c index 3814a6a..9600901 100644 --- a/localtime.c +++ b/localtime.c @@ -1709,8 +1709,9 @@ tmcomp(register const struct tm *const atmp, { register int result; - if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && - (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && + if (atmp->tm_year != btmp->tm_year) + return atmp->tm_year < btmp->tm_year ? -1 : 1; + if ((result = (atmp->tm_mon - btmp->tm_mon)) == 0 && (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && (result = (atmp->tm_min - btmp->tm_min)) == 0) -- 1.8.1.2