<div dir="ltr"><div><br></div><div>Hi,<br><br></div><div>I found that sometimes the localtime() won't work properly, if sp->defaulttype is not set properly.  For example, given the following code:<br><br>    time_t epoch = 0;<br>
<br>    setenv("TZ", "UTC+00", 1);<br>    tzset();<br>    printf("%s", ctime(&epoch)); // (a)<br><br>    setenv("TZ", "Asia/Taipei", 1);<br>    tzset();<br>    printf("%s", ctime(&epoch)); // (b)<br>
<br>    setenv("TZ", "UTC+00", 1);<br>    tzset();<br>    printf("%s", ctime(&epoch)); // (c)<br><br>The expected output should be:<br><br>    Thu Jan  1 00:00:00 1970<br>    Thu Jan  1 08:00:00 1970<br>
    Thu Jan  1 00:00:00 1970<br><br>However, the output is:<br><br>    Thu Jan  1 00:00:00 1970<br>    Thu Jan  1 08:00:00 1970<br>    Thu Jan  1 08:00:00 1970<br><br></div><div>This is due to the fact that sp->defaulttype is set to 1 when we are using "Asia/Taipei" as the timezone, but it is not reset after we change the timezone to "UTC+00".  As the result, the old value in sp->types[sp->defaulttype] is incorrectly used.  The attached patch should resolve this issue.  Please have a look.  Thanks.<br>
<br></div><div>Sincerely,<br>Logan<br></div></div>