From f5d6c1d7d9665fb74eea593893d6fdbf245a9c14 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 8 Dec 2024 23:13:42 -0800
Subject: [PROPOSED] Invalid TZ now abbreviates as "-00" not "UTC"

(Thanks to Arthur David Olson.)
* NEWS: Mention this.
* localtime.c (tzset_unlocked): Implement it.
---
 NEWS        | 4 ++++
 localtime.c | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 2fc7bb19..bf560e21 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,10 @@ Unreleased, experimental changes
     strftime now outputs an invalid conversion specifier as-is,
     instead of eliding the leading '%', which confused debugging.
 
+    An invalid TZ now generates the time zone abbreviation "-00", not
+    "UTC", to help the user see that an error has occurred.  (Thanks
+    to Arthur David Olson for suggesting a "wrong result".)
+
     mktime and timeoff no longer incorrectly fail merely because a
     struct tm component near INT_MIN or INT_MAX overflows when a
     lower-order component carries into it.
diff --git a/localtime.c b/localtime.c
index da257a7f..fb0ea731 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1468,8 +1468,10 @@ tzset_unlocked(void)
     lclptr = sp = malloc(sizeof *lclptr);
 # endif
   if (sp) {
-    if (zoneinit(sp, name) != 0)
+    if (zoneinit(sp, name) != 0) {
       zoneinit(sp, "");
+      strcpy(sp->chars, UNSPEC);
+    }
     if (0 < lcl)
       strcpy(lcl_TZname, name);
   }
-- 
2.47.0

