Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site trwrb.UUCP Path: utzoo!watmath!clyde!akgua!sdcsvax!bmcg!cepu!trwrba!trwrb!gorlick From: gorlick@trwrb.UUCP Newsgroups: net.unix-wizards Subject: Bug in gtime(3) in 4.xbsd Message-ID: <782@trwrb.UUCP> Date: Wed, 9-May-84 16:10:52 EDT Article-I.D.: trwrb.782 Posted: Wed May 9 16:10:52 1984 Date-Received: Sat, 12-May-84 09:37:23 EDT Organization: TRW EDS, Redondo Beach, CA Lines: 71 1984-0020 TRW/UNIX Modification 1984-0020 NAME gmtime - may return incorrect day of the month DATE ENACTED May 9, 1984 KEYWORDS ctime(3), localtime(3), gmtime(3) PROBLEM DESCRIPTION Under rare circumstances gmtime(3) could return the incorrect day of the month. BACKGROUND In determining the day of the month for a leap year (the field tm_mday in the structure tm defined in ) the routine gmtime() will modify the static global table dmsize which contains the number of days in each month of the year. Once a short calculation is completed dmsize is reset to its original values (for a non-leap year). If a signal occurs and is fielded between the modification and the reset the table dmsize can be left in a modified state. Potentially the next call to gmtime(3) can return a value in the field tm_mday that is off by 1. RESOLUTION Change the declaration for dmsize from static int dmsize[12] = to static short dmsize[12] = and create a companion table, dmleap, for leap years static short dmleap[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 }; In the routine gmtime() change the code if (dysize(d1)==366) dmsize[1] = 29; for(d1=0; d0 >= dmsize[d1]; d1++) d0 -= dmsize[d1]; dmsize[1] = 28; to if (dysize(d1)==366) for (d1=0; d0 >= dmleap[d1]; d1++) d0 -= dmleap[d1]; else for (d1=0; d0 >= dmsize[d1]; d1++) d0 -= dmsize[d1]; FILES /usr/src/libc/gen/ctime.c REQUESTOR Michael Gorlick AUTHOR Michael Gorlick {decvax, ucbvax}!trwrb!gorlick This flaw exists in V7 and System V as well.