Subject: bug#21020: 24.4; `display-time-world' tampers with TZ

From: Paul Eggert <[email-masked]>
Date: Mon, 27 Jul 2015 18:09:37 -0700

Eli Zaretskii wrote:
> I'm not even sure I
> understand completely why this trick is needed (can you explain?).

On many platforms, calling 'tzset' (either directly, or indirectly via localtime 
etc.) invalidates tzname[0] and tzname[1].  For example:

    time_t t = 0;
    char *p = tzname[0];
    localtime (&t);
    puts (p ? p : "(null)");

Here 'puts' has undefined behavior if tzname[0] has been updated and its old 
value (equal to P) is no longer a valid pointer.

lib/time_rz.c attempted to work around this problem by replacing tzname[0] and 
tzname[1] with pointers to more-stable copies.  Apparently this doesn't work 
under MinGW.

 > can we please do this in some less intrusive way, e.g., by
 > copying the TZ names to our private storage?

OK, I did that in master commit 2856b1dd6f0ff5164eb5a54ddfadb9963f9e9237.