]> Savannah Git Hosting - gnulib.git/commitdiff
nstrftime: Fix crash on NetBSD 10.0.
authorBruno Haible <bruno@clisp.org>
Tue, 18 Jun 2024 12:58:30 +0000 (14:58 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 18 Jun 2024 12:59:17 +0000 (14:59 +0200)
* lib/strftime.c (utc_timezone_cache): New variable.
(utc_timezone): New function.
(underlying_strftime): Use it when tz is NULL.

ChangeLog
lib/strftime.c

index cb4444907695c26ebf0bc2da4a640dfe45f3f247..0c39edd886f9da1e3e5a6ca9790beb43d46fa2c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-06-18  Bruno Haible  <bruno@clisp.org>
+
+       nstrftime: Fix crash on NetBSD 10.0.
+       * lib/strftime.c (utc_timezone_cache): New variable.
+       (utc_timezone): New function.
+       (underlying_strftime): Use it when tz is NULL.
+
 2024-06-18  Bruno Haible  <bruno@clisp.org>
 
        c-nstrftime: Fix warning on platforms without strftime_l.
index a757b4f313e28e41e5d6adb4b0083cc39c6d7b01..ffc1670f2384db82673167839156d31a6ca94d45 100644 (file)
@@ -403,6 +403,25 @@ c_locale (void)
 
 #endif
 
+#if HAVE_NATIVE_TIME_Z
+
+/* Cache for the UTC time zone object.
+   Marked volatile so that different threads see the same value
+   (avoids locking).  */
+static volatile timezone_t utc_timezone_cache;
+
+/* Return the UTC time zone object, or (timezone_t) 0 with errno set
+   if it cannot be created.  */
+static timezone_t
+utc_timezone (void)
+{
+  if (!utc_timezone_cache)
+    utc_timezone_cache = tzalloc ("UTC");
+  return utc_timezone_cache;
+}
+
+#endif
+
 
 #if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
 
@@ -877,6 +896,15 @@ underlying_strftime (timezone_t tz, char *ubuf, size_t ubufsize,
   *u++ = format_char;
   *u = '\0';
 
+# if HAVE_NATIVE_TIME_Z
+  if (!tz)
+    {
+      tz = utc_timezone ();
+      if (!tz)
+        return 0; /* errno is set here */
+    }
+# endif
+
 # if !HAVE_NATIVE_TIME_Z
   if (tz && tz != local_tz)
     {