From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14828 invoked by alias); 16 Oct 2007 11:34:51 -0000 Received: (qmail 14808 invoked by uid 22791); 16 Oct 2007 11:34:51 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 16 Oct 2007 11:34:48 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l9GBcIFq016112; Tue, 16 Oct 2007 13:38:18 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l9GBcISu016108; Tue, 16 Oct 2007 13:38:18 +0200 Date: Tue, 16 Oct 2007 11:34:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] tzfile.c fixes Message-ID: <20071016113817.GK2896@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-10/txt/msg00016.txt.bz2 Hi! TZ=Asia/Tokyo date since last tzfile.c changes shows 1hr more than actually is and JDT for 32-bit date (and correct time and timezone for 64-bit date). The difference is that for 32-bit libc we don't read the TZif2 part of the zoneinfo file nor the POSIX string in it, and after the use_last label the new code sets i to num_transitions - 1 and at found it looks at i - 1 (i.e. num_transitions - 2). The following patch fixes that, as well as assertion failure on tst-mktime2 on 32-bit - e.g. for America/Sao_Paulo if time is in between last transition and 0x7fffffff and last transition is dst, then __tzname[0] == NULL, __tzname[1] = "something" and num_types > 1. Generally, the forward search doesn't have to find the other __tzname if i is sufficiently close to num_transitions, so I think it is best to search backwards if the forward search doesn't help. 2007-10-16 Jakub Jelinek * time/tzfile.c (__tzfile_compute): For use_last case set i to num_transition rather than num_transitions - 1. If forward search for other __tzname didn't find it, search backwards. --- libc/time/tzfile.c.jj 2007-10-16 09:50:03.000000000 +0200 +++ libc/time/tzfile.c 2007-10-16 13:10:25.000000000 +0200 @@ -596,7 +596,7 @@ __tzfile_compute (time_t timer, int use_ if (tzspec == NULL) { use_last: - i = num_transitions - 1; + i = num_transitions; goto found; } @@ -666,7 +666,8 @@ __tzfile_compute (time_t timer, int use_ i = hi; found: - /* assert (timer >= transitions[i - 1] && timer < transitions[i]); */ + /* assert (timer >= transitions[i - 1] + && (i == num_transitions || timer < transitions[i])); */ __tzname[types[type_idxs[i - 1]].isdst] = __tzstring (&zone_names[types[type_idxs[i - 1]].idx]); size_t j = i; @@ -681,12 +682,30 @@ __tzfile_compute (time_t timer, int use_ __tzname[dst] = __tzstring (&zone_names[idx]); if (__tzname[1 - dst] != NULL) - break; + goto got_tznames; } ++j; } + j = i - 1; + while (j > 0) + { + int type = type_idxs[--j]; + int dst = types[type].isdst; + int idx = types[type].idx; + + if (__tzname[dst] == NULL) + { + __tzname[dst] = __tzstring (&zone_names[idx]); + + if (__tzname[1 - dst] != NULL) + goto got_tznames; + } + } + __tzname[1 - types[type_idxs[i - 1]].isdst] + = __tzname[types[type_idxs[i - 1]].isdst]; + got_tznames: i = type_idxs[i - 1]; } Jakub