+2024-06-18 Paul Eggert <eggert@cs.ucla.edu>
+
+ nstrftime: tweak volatile access
+ * lib/strftime.c (utc_timezone): Avoid unnecessary access to volatile.
+
2024-06-18 Bruno Haible <bruno@clisp.org>
nstrftime: Fix crash on NetBSD 10.0.
#if HAVE_NATIVE_TIME_Z
-/* Cache for the UTC time zone object.
- Marked volatile so that different threads see the same value
- (avoids locking). */
+/* On NetBSD a null tz has undefined behavior, so use a non-null tz.
+ Cache the UTC time zone object in a volatile variable for improved
+ thread safety. This is good enough in practice, although in theory
+ stdatomic.h should be used. */
static volatile timezone_t utc_timezone_cache;
/* Return the UTC time zone object, or (timezone_t) 0 with errno set
static timezone_t
utc_timezone (void)
{
- if (!utc_timezone_cache)
- utc_timezone_cache = tzalloc ("UTC");
- return utc_timezone_cache;
+ timezone_t tz = utc_timezone_cache;
+ if (!tz)
+ utc_timezone_cache = tz = tzalloc ("UTC0");
+ return tz;
}
#endif