[tz] [PATCH] Initialize sp->defaulttype in tzparse()

Logan Chien tzuhsiang.chien at gmail.com
Wed Jan 1 04:42:32 UTC 2014


Hi,

I found that sometimes the localtime() won't work properly, if
sp->defaulttype is not set properly.  For example, given the following code:

    time_t epoch = 0;

    setenv("TZ", "UTC+00", 1);
    tzset();
    printf("%s", ctime(&epoch)); // (a)

    setenv("TZ", "Asia/Taipei", 1);
    tzset();
    printf("%s", ctime(&epoch)); // (b)

    setenv("TZ", "UTC+00", 1);
    tzset();
    printf("%s", ctime(&epoch)); // (c)

The expected output should be:

    Thu Jan  1 00:00:00 1970
    Thu Jan  1 08:00:00 1970
    Thu Jan  1 00:00:00 1970

However, the output is:

    Thu Jan  1 00:00:00 1970
    Thu Jan  1 08:00:00 1970
    Thu Jan  1 08:00:00 1970

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.

Sincerely,
Logan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mm.icann.org/pipermail/tz/attachments/20140101/43c5e216/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Initialize-sp-defaulttype-in-tzparse.patch
Type: text/x-diff
Size: 2003 bytes
Desc: not available
URL: <http://mm.icann.org/pipermail/tz/attachments/20140101/43c5e216/0001-Initialize-sp-defaulttype-in-tzparse.patch>


More information about the tz mailing list