Article View: news.software.nn
Article #9443Re: nn 6.5.5 pack_date mishandles some dates
From: Michael T Pins
Date: Sat, 05 Feb 2000 00:00
Date: Sat, 05 Feb 2000 00:00
53 lines
2992 bytes
2992 bytes
eggert@twinsun.com (Paul Eggert) writes:
>nn 6.5.5 has a new version of pack_date, but it mishandles some dates,
>and this causes messages to be displayed out of order. For example,
>pack_date("31 Jan 2000 10:46:25 -0500") yields 951493585, but
>pack_date("01 Feb 2000 17:19:14 -0500") yields 951430754.
*ack*
This bug was your basic off-by-one bug. ( "<=" instead of "<" )
>While fixing this problem, I noticed some other problems:
>* Time stamps near the end of a leap-year are mishandled.
This was a remnant of an attempt to turn it into a real timestamp for
something else in nn7. A course I abandoned, but obviously neglected to
fully clean up after. Thanks for the pointers.
>* pack_date uses `isdigit((int) ch)', where `ch' is a character, in
> the apparent belief that the cast to int is needed. But that cast
> doesn't help: if ch is negative, the result is undefined (and can
> dump core). The correct way to use ctype macros on chars is to cast
> their arguments to unsigned char, e.g. `isdigit((unsigned char) ch)'.
According to the C standard, a cast to int *is* required.
SYNOPSIS
#include <ctype.h>
int isdigit(int c);
While all characters must be representable as an unsigned char, EOF is not
so constrained, and is, in fact, (-1) on most systems.
The correct way to do it is to cast it to int, which is what I'm doing.
>* The code could be sped up (I couldn't resist doing this :-).
Well, sort of.
I ran both your version and my version on a group of 2000 entries. On my
old Sparc5, they both finished so fast that the micro-second counter never
registered. On my ancient 486, on 2000 entries, my version took 0.29 sec,
yours took 0.25 sec. While technically yours is faster, 4/100 seconds
(on 2000 entries) isn't really perceivable.
I've put nn-6.5.6 up, which includes both the fix for the time-sort bugs
(gads that's embarrassing) and the workaround for the new brain-damage
in Solaris7's header files.
--
**************************************************************************
* Michael T Pins | mtpins@visi.com *
* keeper of the nn sources | mtpins@icaen.uiowa.edu *
* ftp://ftp.visi.com/users/mtpins | #include <std.disclaimer> *
Technical Details
Message-ID:
<ve0n4.1456$8p3.176032@ptah.visi.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nn.mbox.zip!not-for-mailReferences:
<87fa3a$7j9$1@shade.twinsun.com>Show Full Headers
Complete Article Headers
Message-ID: <ve0n4.1456$8p3.176032@ptah.visi.com> Subject: Re: nn 6.5.5 pack_date mishandles some dates Date: Sat, 05 Feb 2000 00:00:00 +0000 From: mtpins@visi.com (Michael T Pins) References: <87fa3a$7j9$1@shade.twinsun.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nn.mbox.zip!not-for-mail X-Deja-AN: 582031293 X-Complaints-To: abuse@visi.com X-Trace: ptah.visi.com 949784603 209.98.143.84 (Sat, 05 Feb 2000 15:03:23 CST) NNTP-Posting-Date: Sat, 05 Feb 2000 15:03:23 CST Newsgroups: news.software.nn