davy@ecn-ee.UUCP (08/26/84)
#N:ecn-ee:16700006:000:566
ecn-ee!davy Aug 25 15:39:00 1984
Subject: asctime(3) dies on years > 1999
Index: /usr/src/lib/libc/gen/ctime.c 4.2BSD
Description:
The asctime() routine will die on dates after Dec 31 23:59:59 1999,
producing a string with an incomplete year.
Repeat-By:
#include <sys/time.h>
main()
{
char *ctime();
long clock = 946702800; /* or anything greater */
printf("Next line should be: Sat Jan 1 00:00:00 2000\n");
printf("%s", ctime(&clock));
}
Fix:
On line 292, change:
cp[2] = '0' + t->tm_year >= 200;
to:
cp[2] = '0';
--Dave Curry
decvax!pur-ee!davy
eevax.davy@purdue
dmmartindale@watcgl.UUCP (Dave Martindale) (09/02/84)
#N:ecn-ee:16700006:000:566 ecn-ee!davy Aug 25 15:39:00 1984 Subject: asctime(3) dies on years > 1999 Index: /usr/src/lib/libc/gen/ctime.c 4.2BSD Description: The asctime() routine will die on dates after Dec 31 23:59:59 1999, producing a string with an incomplete year. Fix: On line 292, change: cp[2] = '0' + t->tm_year >= 200; to: cp[2] = '0'; --Dave Curry decvax!pur-ee!davy eevax.davy@purdue This fix works for years from 2000 to 2099, but blows up for years after 2100. The original bug was due to missing paretheses. The correct fix is to change the line in question to: cp[2] = '0' + (t->tm_year >= 200);