public inbox for gnats-devel@sourceware.org
 help / color / mirror / Atom feed
From: Lars Henriksen <Lars.Henriksen@netman.dk>
To: help-gnats@gnu.org
Cc: Milan Zamazal <pdm@zamazal.org>,
	Yngve Svendsen <yngve.svendsen@sun.com>,
	"Carl E. Lindberg" <lindberg@clindberg.org>
Subject: Wrong dates in PRs if no %z support in strftime(3)
Date: Thu, 12 Sep 2002 15:07:00 -0000	[thread overview]
Message-ID: <20020912142837.GA1438328@cluster2.netman.dk> (raw)
In-Reply-To: <5.1.0.14.2.20010612221913.00ba0828@10.10.1.1>

On Tue, Jun 12, 2001 at 10:25:02PM +0200, Yngve Svendsen wrote:
> At 17:19 12.06.2001 +0200, Yngve Svendsen wrote:
> >At 17:15 10.06.2001 +0200, Milan Zamazal wrote:
> >>>>>>> "YS" == Yngve Svendsen <yngve.svendsen@clustra.com> writes:
> >>
> >>    YS> Sorry, but it seems the configure check for %z support isn't
> >>    YS> working right.
> >>
> >>You're right.  strftime is going to become my nightmare. :-|  I tried to
> >>fix it and also added a patch by Carl enabling numeric time zones also
> >>on systems not supporting `%z'.  Please try whether it works or not.
> >
> >Unfortunately, the nightmare continues. "make all" results in the 
> >following on a Solaris 7 system:
> 
> [snip]
> 
> On some systems, Solaris among them, isdigit() requires an explicit cast to 
> int. The very simple patch below fixes the problem and makes the current 
> GNATS 4 compile on both Solaris and Linux.
> 
> I have compiled and done some testing, and as far as I can tell, all is now 
> well on systems that don't support %z.

Not quite.

There is a bug in gnats_strftime() that affects systems without %z support.
The problem is the brokentime pointer passed to gnats_strftime(). It points
to static data that may be overwritten by calls to (among others) gmtime().

Exactly this happens in the support routine minutes_gmt_offset(), whereupon
brokentime is passed on to strftime().

Patch follows. I have submitted a gnats PR as well.

Lars Henriksen

Index: misc.c
===================================================================
RCS file: /cvsroot/gnats/gnats/gnats/misc.c,v
retrieving revision 1.36
diff -u -r1.36 misc.c
--- misc.c      6 Jan 2002 16:13:20 -0000       1.36
+++ misc.c      12 Sep 2002 14:16:12 -0000
@@ -568,6 +568,11 @@
       char *fixed_template = (char*)xmalloc (strlen(template)+FORMAT_PADDING);
       const char *in = template;
       char *out = fixed_template;
+      /* Because brokentime points to static data (allocated
+       * by localtime()), it cannot be passed to a subroutine
+       * and then later be relied on to point to the same data. */
+      struct tm bktime = *brokentime;
+      int result;
      
       while (*in != '\0')
        {
@@ -602,12 +607,9 @@
            }
        }
       *out = '\0';
-    
-      {
-       int result = strftime (s, size, fixed_template, brokentime);
-       free (fixed_template);
-       return result;
-      }
+      result = strftime (s, size, fixed_template, &bktime);
+      free (fixed_template);
+      return result;
     }
 }



_______________________________________________
Help-gnats mailing list
Help-gnats@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gnats

      parent reply	other threads:[~2002-09-12 14:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-10 16:37 Current Gnats 4 CVS broken on Solaris Yngve Svendsen
2001-05-27  8:36 ` Milan Zamazal
2001-05-30  8:51   ` Yngve Svendsen
2001-06-10 10:26     ` Milan Zamazal
2001-06-12  8:21       ` Yngve Svendsen
2001-06-12 13:23         ` Yngve Svendsen
2001-06-13 10:33           ` Milan Zamazal
2002-09-12 15:07           ` Lars Henriksen [this message]

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=20020912142837.GA1438328@cluster2.netman.dk \
    --to=lars.henriksen@netman.dk \
    --cc=help-gnats@gnu.org \
    --cc=lindberg@clindberg.org \
    --cc=pdm@zamazal.org \
    --cc=yngve.svendsen@sun.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).