America/Chicago zone vs mktime w/tm_isdst!=-1

Paul Eggert eggert at twinsun.com
Sat Dec 6 00:02:15 UTC 2003


Dan Nelson [mailto:dnelson at allantgroup.com] writes:

> it's troublesome if the behaviour changes from zone to zone, and the
> current releases of Solaris, Tru64, AIX, and glibc(Linux) are
> consistent across timezones (they all adjust the incoming struct tm
> based on tm_isdst).

It seems clear to me that this is a bug in tzcode.

The following patch fixes the problem on your test case, making tzcode
act like Solaris and glibc except in the "could be either" case with
isdst=-1 (which is clearly implementation-defined behavior).

However, I should warn that I haven't a clue as to why this patch
"works", and I suspect there are other examples where it won't work.
I derived this patch merely by doing a diff between classic tzcode and
current tzcode, and looking for "suspicious" changes.

--- localtime.c	2003-09-16 04:12:40.000000000 -0700
+++ localtime1.c	2003-12-05 15:56:17.326492000 -0800
@@ -1536,10 +1536,10 @@ const long		offset;
 	if (sp == NULL)
 		return WRONG;
 #endif /* defined ALL_STATE */
-	for (samei = sp->typecnt - 1; samei >= 0; --samei) {
+	for (samei = 0; samei < sp->typecnt; samei++) {
 		if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
 			continue;
-		for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) {
+		for (otheri = 0; otheri < sp->typecnt; otheri++) {
 			if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
 				continue;
 			tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -



More information about the tz mailing list