🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #10103

Patch for calentool (dormant bug awoke in 1989)

#10103
From: Jacob Gore
Date: Sat, 07 Jan 1989 04:59
63 lines
2907 bytes
There is a bug in calentool that showed up when 1989 rolled around.  The
symptom is that it believes that today is yesterday.

The fundamental problem is in array year_days in utils.c.  They key is
that each location stores the number of days between the beginning of 1985
and the BEGINNING of the year, not to its end.  Thus, the fact that 1988
is a leap year adds 1 to 1989's location, not to 1988 (in the beginning of
1988, the leap year has not taken toll yet).

This, of course, should have made it NOT work in 1988, because in 1988 an
extra day is added, and work again in 1989, because in 1989 one day too
few is added, to make it in step again.  My feeling is that it didn't work
in 1988, and that's why there is a "- 1" in the computation, to compensate
for the bug.  The "- 1" screws things up in 1989, however. 

The following patch fixes that data in the array, and removes the "- 1",
which I very strongly suspect to be a kluge.

[[ I have received messages from several readers complaining about the
same bug.  This was the only one with a patch.  I don't intend to post the
other messages for obvious reasons.  Thanks to all who pointed out the
problem and worked on debugging it.  --wnl ]]

Jacob Gore				Gore@EECS.NWU.Edu
Northwestern Univ., EECS Dept.		{oddjob,gargoyle,att}!nucsrl!gore

*** /tmp/,RCSt1005087	Wed Jan  4 23:17:51 1989
--- utils.c	Wed Jan  4 23:02:30 1989
***************
*** 90,97 ****

  /* cummulative number of days since Jan 1, 1985 by years to 1999 */
  /* (takes into account leap years in 1988, 1992, 1996) */
! int year_days[] = {0, 365, 730, 1096, 1461, 1826, 2191, 2557, 2922,
! 			3287, 3652, 4018, 4383, 4748, 5113};

  get_today()
  {
--- 90,97 ----

  /* cummulative number of days since Jan 1, 1985 by years to 1999 */
  /* (takes into account leap years in 1988, 1992, 1996) */
! int year_days[] = {0, 365, 730, 1095, 1461, 1826, 2191, 2556, 2922,
! 			3287, 3652, 4017, 4383, 4748, 5113};

  get_today()
  {
***************
*** 101,107 ****

  	gettimeofday(&tv, 0);
  	tm = localtime(&tv.tv_sec);
! 	t = tm->tm_yday + year_days[tm->tm_year-85] - year_days[START_YEAR-85] - 1;
  	return(t);
  }

--- 101,107 ----

  	gettimeofday(&tv, 0);
  	tm = localtime(&tv.tv_sec);
! 	t = tm->tm_yday + year_days[tm->tm_year-85] - year_days[START_YEAR-85];
  	return(t);
  }
Technical Details
Message-ID: <8901042331.aa05103@gamma.eecs.nwu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!lll-winken!ames!mailrus!cornell!uw-beaver!rice!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!lll-winken!ames!mailrus!cornell!uw-beaver!rice!sun-spots-request
From: gore@eecs.nwu.edu (Jacob Gore)
Newsgroups: comp.sys.sun
Subject: Patch for calentool (dormant bug awoke in 1989)
Message-ID: <8901042331.aa05103@gamma.eecs.nwu.edu>
Date: 7 Jan 89 04:59:45 GMT
Sender: usenet@rice.edu
Organization: U of Maryland, Dept. of Computer Science,gs
Lines: 63
Approved: Sun-Spots@rice.edu
Original-Date: Wed, 4 Jan 89 23:31:14 CST
X-Sun-Spots-Digest: Volume 7, Issue 91, message 13 of 13