Index: generic/tclClock.c ================================================================== --- generic/tclClock.c +++ generic/tclClock.c @@ -2005,25 +2005,28 @@ static void TzsetIfNecessary(void) { static char *tzWas = NULL; /* Previous value of TZ, protected by * clockMutex. */ + static char first = 0; /* First time? */ const char *tzIsNow; /* Current value of TZ */ Tcl_MutexLock(&clockMutex); tzIsNow = getenv("TZ"); - if (tzIsNow != NULL && (tzWas == NULL || strcmp(tzIsNow, tzWas) != 0)) { + int mod = ((size_t)tzWas ^ (size_t)tzIsNow) || + ((size_t)tzWas & (size_t)tzIsNow && strcmp(tzIsNow, tzWas) != 0); + if (first || mod) { + first = 0; tzset(); if (tzWas != NULL) { ckfree(tzWas); + tzWas = NULL; } - tzWas = ckalloc(strlen(tzIsNow) + 1); - strcpy(tzWas, tzIsNow); - } else if (tzIsNow == NULL && tzWas != NULL) { - tzset(); - ckfree(tzWas); - tzWas = NULL; + if (tzIsNow != NULL) { + tzWas = ckalloc(strlen(tzIsNow) + 1); + strcpy(tzWas, tzIsNow); + } } Tcl_MutexUnlock(&clockMutex); } /*