From ae51419546a4a8c98d9379d4d9cd6b25c79f2df4 Mon Sep 17 00:00:00 2001 From: Manuel Novoa III Date: Mon, 25 Jul 2005 03:50:55 +0000 Subject: Fix 2 bugs in strftime related to glibc struct tm extensions. 1) Need to negate tm_gmtoff field value when used. (bug 336). 2) Deal with NULL ptr case for tm_zone field, which was causing segfaults in both the NIST/PCTS tests and the Python 2.4.1 self-test suite. NOTE: We set uninitialized timezone names to "???", and this differs (intentionally) from glibc's behavior. --- libc/misc/time/time.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'libc/misc/time') diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c index 5cef91787..f43bb8a3c 100644 --- a/libc/misc/time/time.c +++ b/libc/misc/time/time.c @@ -118,6 +118,15 @@ * Make lookup_tzname() static (as it should have been). * Have strftime() get timezone information from the passed struct * for the %z and %Z conversions when using struct tm extensions. + * + * Jul 24, 2004 + * Fix 2 bugs in strftime related to glibc struct tm extensions. + * 1) Need to negate tm_gmtoff field value when used. (bug 336). + * 2) Deal with NULL ptr case for tm_zone field, which was causing + * segfaults in both the NIST/PCTS tests and the Python 2.4.1 + * self-test suite. + * NOTE: We set uninitialized timezone names to "???", and this + * differs (intentionally) from glibc's behavior. */ #define _GNU_SOURCE @@ -1066,7 +1075,7 @@ size_t __XL(strftime)(char *__restrict s, size_t maxsize, #define RSP_TZUNLOCK ((void) 0) #define RSP_TZNAME timeptr->tm_zone -#define RSP_GMT_OFFSET timeptr->tm_gmtoff +#define RSP_GMT_OFFSET (-timeptr->tm_gmtoff) #else @@ -1084,6 +1093,20 @@ size_t __XL(strftime)(char *__restrict s, size_t maxsize, if (*p == 'Z') { o = RSP_TZNAME; +#ifdef __UCLIBC_HAS_TM_EXTENSIONS__ + /* Sigh... blasted glibc extensions. Of course we can't + * count on the pointer being valid. Best we can do is + * handle NULL, which looks to be all that glibc does. + * At least that catches the memset() with 0 case. + * NOTE: We handle this case differently than glibc! + * It uses system timezone name (based on tm_isdst) in this + * case... although it always seems to use the embedded + * tm_gmtoff value. What we'll do instead is treat the + * timezone name as unknown/invalid and return "???". */ + if (!o) { + o = "???"; + } +#endif assert(o != NULL); #if 0 if (!o) { /* PARANOIA */ -- cgit v1.2.3