public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] tzfile.c fixes
Date: Tue, 16 Oct 2007 11:34:00 -0000	[thread overview]
Message-ID: <20071016113817.GK2896@sunsite.mff.cuni.cz> (raw)

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  <jakub@redhat.com>

	* 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

             reply	other threads:[~2007-10-16 11:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-16 11:34 Jakub Jelinek [this message]
2007-10-16 15:31 ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071016113817.GK2896@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).