# HG changeset patch # User Jim Meyering # Date 775195586 0 # Node ID 63297bb8f1ddb58b1b9d46afa796c4a346ba54aa # Parent ea96d91a16768becb6e0962bc250ef923253771c merge with 1.10f diff -r ea96d91a1676 -r 63297bb8f1dd lib/mktime.c --- a/lib/mktime.c Sat Jul 23 04:42:46 1994 +0000 +++ b/lib/mktime.c Tue Jul 26 04:06:26 1994 +0000 @@ -1,5 +1,6 @@ /* Copyright (C) 1993, 1994 Free Software Foundation, Inc. - Contributed by Noel Cragg (noel@cs.oberlin.edu). + Contributed by Noel Cragg (noel@cs.oberlin.edu), with fixes + by Michael E. Calwas (calwas@ttd.teradyne.com). This file is part of the GNU C Library. @@ -226,12 +227,12 @@ while (me->foo < x) \ { \ me->bar--; \ - me->foo = (y - (x - me->foo)); \ + me->foo = (y - (x - me->foo) + 1); \ } \ while (me->foo > y) \ { \ + me->foo = (x + (me->foo - y) - 1); \ me->bar++; \ - me->foo = (x + (me->foo - y)); \ } normalize (tm_sec, 0, 59, tm_min); @@ -240,8 +241,14 @@ /* Do the month first, so day range can be found. */ normalize (tm_mon, 0, 11, tm_year); + + /* Since the day range modifies the month, we should be careful how + we reference the array of month lengths -- it is possible that + the month will go negative, hence the %... */ normalize (tm_mday, 1, - __mon_lengths[__isleap (me->tm_year)][me->tm_mon], + __mon_lengths[__isleap (me->tm_year)][((me->tm_mon < 0) + ? (12 + (me->tm_mon % 12)) + : (me->tm_mon % 12)) ], tm_mon); /* Do the month again, because the day may have pushed it out of range. */ @@ -249,7 +256,9 @@ /* Do the day again, because the month may have changed the range. */ normalize (tm_mday, 1, - __mon_lengths[__isleap (me->tm_year)][me->tm_mon], + __mon_lengths[__isleap (me->tm_year)][((me->tm_mon < 0) + ? (12 + (me->tm_mon % 12)) + : (me->tm_mon % 12)) ], tm_mon); #ifdef DEBUG