help-gnats
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Wrong dates in PRs if no %z support in strftime(3)


From: Lars Henriksen
Subject: Wrong dates in PRs if no %z support in strftime(3)
Date: Thu, 12 Sep 2002 16:28:38 +0200
User-agent: Mutt/1.4i

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 <address@hidden> 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;
     }
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]