Subject: bin/5830: [PATCH] Broken date calculation in adventure
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 07/24/1998 14:22:42
>Number: 5830
>Category: bin
>Synopsis: [PATCH] Broken date calculation in adventure
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jul 24 10:05:01 1998
>Last-Modified:
>Originator: Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release: NetBSD-current of 1998-07-11
>Environment:
[
System: Linux octomino 2.0.35 #1 Tue Jul 14 19:09:50 UTC 1998 i586 unknown
Architecture: i586
]
>Description:
This bug was found in year 2000 compliance checks on the Linux port of
the NetBSD games. adventure computes the number of days since the
start of 1977 using a formula that completely ignores leap years:
while not specifically a year 2000 issue this is clearly broken. The
patch below fixes this.
>How-To-Repeat:
The bug could cause problems if you save at the end of a leap year and
try to restore the next day (untested).
>Fix:
--- adventure/wizard.c Sat Oct 11 11:49:28 1997
+++ adventure+/wizard.c Fri Jul 24 14:06:01 1998
@@ -65,9 +65,11 @@
time(&tvec);
tptr = localtime(&tvec);
- /* day since 1977 (mod leap) */
- *d = tptr->tm_yday + 365 * (tptr->tm_year - 77);
- /* bug: this will overflow in the year 2066 AD */
+ /* day since 1977 */
+ *d = (tptr->tm_yday + 365 * (tptr->tm_year - 77)
+ + (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100
+ + (tptr->tm_year + 299) / 400);
+ /* bug: this will overflow in the year 2066 AD (with 16 bit int) */
/* it will be attributed to Wm the C's millenial celebration */
/* and minutes since midnite */
*t = tptr->tm_hour * 60 + tptr->tm_min;
>Audit-Trail:
>Unformatted: