This is the mail archive of the
newlib-cvs@sourceware.org
mailing list for the newlib project.
[newlib-cygwin/cygwin-2.0] strftime: use tzname if TM_ZONE is NULL
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: newlib-cvs at sourceware dot org
- Date: 23 Apr 2015 20:49:26 -0000
- Subject: [newlib-cygwin/cygwin-2.0] strftime: use tzname if TM_ZONE is NULL
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=95a4fc87264e5fdeb5452d63d3b2df217a2f19b2
commit 95a4fc87264e5fdeb5452d63d3b2df217a2f19b2
Author: Yaakov Selkowitz <yselkowi@redhat.com>
Date: Wed Mar 25 16:26:07 2015 -0500
strftime: use tzname if TM_ZONE is NULL
This avoids a strlen(NULL) crash a few lines later.
* libc/time/strftime.c (strftime) <%Z>: Initialize tznam to NULL.
Use _tzname as fallback if TM_ZONE is NULL.
Diff:
---
newlib/ChangeLog | 5 +++++
newlib/libc/time/strftime.c | 6 +++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 7c57c94..6e45e94 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,5 +1,10 @@
2015-03-30 Yaakov Selkowitz <yselkowi@redhat.com>
+ * libc/time/strftime.c (strftime) <%Z>: Initialize tznam to NULL.
+ Use _tzname as fallback if TM_ZONE is NULL.
+
+2015-03-30 Yaakov Selkowitz <yselkowi@redhat.com>
+
* libc/include/libgen.h (_BASENAME_DEFINED): Define.
* libc/include/string.h (basename): Declare.
* libc/string/Makefile.am (ELIX_4_SOURCES): Add gnu_basename.c.
diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c
index 7db3383..ee604c2 100644
--- a/newlib/libc/time/strftime.c
+++ b/newlib/libc/time/strftime.c
@@ -1311,7 +1311,7 @@ recurse:
if (tim_p->tm_isdst >= 0)
{
size_t size;
- const char *tznam;
+ const char *tznam = NULL;
TZ_LOCK;
#if defined (__CYGWIN__)
@@ -1320,9 +1320,9 @@ recurse:
tznam = __cygwin_gettzname (tim_p);
#elif defined (__TM_ZONE)
tznam = tim_p->__TM_ZONE;
-#else
- tznam = _tzname[tim_p->tm_isdst > 0];
#endif
+ if (!tznam)
+ tznam = _tzname[tim_p->tm_isdst > 0];
/* Note that in case of wcsftime this loop only works for
timezone abbreviations using the portable codeset (aka ASCII).
This seems to be the case, but if that ever changes, this