
From grdetil@scrc.umanitoba.ca Fri Jan  7 23:03:31 2000
Date: Fri, 7 Jan 2000 13:10:50 -0600 (CST)
From: Gilles Detillieux <grdetil@scrc.umanitoba.ca>
To: jjah@cloud.ccsf.cc.ca.us
Subject: [htdig] PATCH: fix strftime segfault bug

Hi, Joe.  Here's a patch I just posted to the htdig bug database, to fix
that nasty strftime segfault problem that keeps recurring.

From: Gilles Detillieux <grdetil@scrc.umanitoba.ca>
Subject: Re: A year 2000 bug (PR#734)
To: raritan@coffee.corliss.net (Raritan CompuSwitch)
Date: Fri, 7 Jan 2000 13:04:56 -0600 (CST)

According to Erin Corliss at Raritan CompuSwitch:
> 'strings <htdig | grep libc' shows that htdig is using libc.so.5, which is
> a symbolic link to /lib/libc.so.5.4.44.
> 
> There's also a libc.so.5.4.33 with an earlier date on it in the /lib
> directory, so I might have spoken too hastily when I said I've never made
> any upgrades to the system.  The newer one is still about 2 years old,
> though...
...
> Htsearch seems to be working fine, even with documents dated after the
> new year, so my solution for now is just not to run with the -vvv option.

OK, I took a look at strftime() in the sources for both libc 5.4.33
and 5.4.46 (I couldn't find a Slackware distribution with 5.4.44 on
ftp.cdrom.com).  I'm pretty sure I have a handle on the problem now,
but it would appear that the fact it only started acting up on your
system after 1999 is purely coincidental.

The problem is that this version of strftime() uses one or two fields
that are not initialised (tm_isdst, and possibly tm_zone), leading to
a segfault.  I think ultimately, Document::getdate() must do away with
using strftime() on the tm structure it initialises itself - it's too
risky, because you don't know what fields various implementations will
require.  Here's a patch that should get htdig -vvv working again:

--- htdig/Document.cc.ftimebug	Thu Dec  9 18:28:44 1999
+++ htdig/Document.cc	Fri Jan  7 12:13:59 2000
@@ -227,7 +227,10 @@ Document::getdate(char *datestring)
 	    char	buffer[100];
 	    // Leave out %a for weekday, because we don't set it anymore...
 	    //strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T", &tm);
-	    strftime(buffer, sizeof(buffer), "%d %b %Y %T", &tm);
+	    // Let's just do away with strftime() altogether for this...
+	    //strftime(buffer, sizeof(buffer), "%d %b %Y %T", &tm);
+	    sprintf(buffer, "%4d-%02d-%02d %02d:%02d:%02d", tm.tm_year+1900,
+		tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
 	    cout << buffer << " (" << tm.tm_year << ")" << endl;
 	  }
 #if HAVE_TIMEGM


-- 
Gilles R. Detillieux              E-mail: <grdetil@scrc.umanitoba.ca>
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
