According to moi:
> Hi, all.  I haven't actually tested it, but upon perusing the code for
> mytimegm(), it seems it won't treat the year 2000 correctly as a leap
> year.
> 
> The LEAP_YEAR() macro is currently:
> 
>   #define LEAP_YEAR(y) (((y)%4 == 0) && ((y)%100 != 0 || (y)%400 == 0))
> 
> This would work fine if it were given the full 4 digit year, but
> it's given tm_year format years, i.e. year-1900.  So, in the year
> 2000, the tm_year will be 100, for which the macro would return 0.
> 
> It seems to me the LEAP_YEAR() macro should be:
> 
>   #define LEAP_YEAR(y) ((((y+1900))%4 == 0) && (((y+1900))%100 != 0 || 
>((y+1900))%400 == 0))

OK, now I have actually tested it.  (I just noticed the test code was
all there.)  Sure enough, it craps out after Feb 28, 2000.  With all
the test cases in there, the author didn't think to test beyond 1997.
Sheesh!  Even worse, configure doesn't seem to test for timegm(), so
everybody's using the buggy mytimegm() function.  So in 12 months and 3
days, everybody's htdig will start storing the wrong modification date
for newly updated documents, unless they install this patch:

--- htlib/mytimegm.cc.y2kbug    Tue Feb 16 23:03:56 1999
+++ htlib/mytimegm.cc   Fri Feb 26 17:10:59 1999
@@ -19,7 +19,7 @@
 
 time_t mytimegm(struct tm *tm)
 {
-  #define LEAP_YEAR(y) (((y)%4 == 0) && ((y)%100 != 0 || (y)%400 == 0))
+  #define LEAP_YEAR(y) ((((y+1900))%4 == 0) && (((y+1900))%100 != 0 || ((y+1900))%400 
+== 0))
 
   static struct tm epoch;
   static int epoch_initialized = 0;
@@ -109,6 +109,13 @@ void main(void)
     "1980.01.01 00:00:05",
     "1984.12.31 23:00:00",
     "1997.06.05 17:55:35",
+    "1999.12.31 23:00:00",
+    "2000.01.01 00:00:05",
+    "2000.02.28 23:00:05",
+    "2000.02.29 23:00:05",
+    "2000.03.01 00:00:05",
+    "2007.06.05 17:55:35",
+    "2038.01.19 03:14:07", /* last UTC second supported by signed 32-bit time_t */
     0
   };
   int i, ok = 1;


-- 
Gilles R. Detillieux              E-mail: <[EMAIL PROTECTED]>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/~grdetil
Dept. Physiology, U. of Manitoba  Phone:  (204)789-3766
Winnipeg, MB  R3E 3J7  (Canada)   Fax:    (204)789-3930
------------------------------------
To unsubscribe from the htdig3-dev mailing list, send a message to
[EMAIL PROTECTED] containing the single word "unsubscribe" in
the SUBJECT of the message.

Reply via email to