[erlang-patches] Fix calendar:local_time_to_universal_time_dst/2 bug of return value -1 from mktime

Kenji Rikitake kenji.rikitake@REDACTED
Thu Feb 11 00:20:20 CET 2010


Bjorn and all:

I would like the mktime fix of erl_time_sup.c to be included ASAP.
(check out
git fetch git://github.com/jj1bdx/otp.git local_to_univ
for the patch details)

In the message <6672d0161002100626y36ab72f4oc451c9478865be75@REDACTED>
dated Wed, Feb 10, 2010 at 03:26:07PM +0100,
Bjorn Gustavsson <bgustavsson@REDACTED> writes:
> We don't want the change in calendar.erl.
> 
> The documentation says that local_time_to_universal_time_dst/1
> returns an empty list for a time that does not exist. We don't want
> the same return value for a valid time that cannot be handled because
> of an implementation detail.

I will not argue against this decision for the time being.

> We may consider using the patch for erl_time_sup.c, if you can
> provide some information to show that it is really needed. Note
> that the BIF does a range check of its arguments. Are there some
> values of the arguments that slip through the range check and
> cause mktime() to return -1?
> 
> Since such a change is considered a bug fix, we can accept
> it after the feature freeze today.

Paul Guyot summarized the case in
http://www.erlang.org/pipermail/erlang-bugs/2008-November/001077.html
as:

(quote)

"I found a bug in Erlang/OTP R12B-4 that occurs on FreeBSD 7.0 with TZ
set to UTC. On such systems, mktime(3) returns -1 when is_dst is set
to true. According to SUSv3, the OS can return -1 when the time since
Epoch cannot be represented, and therefore FreeBSD is perfectly
allowed to do so.

http://www.opengroup.org/onlinepubs/009695399/functions/mktime.html
"
(unquote)

The POSIX doc for mktime in the above opengroup.org link shows the
following definition for the return value:

(quote)
RETURN VALUE

    The mktime() function shall return the specified time since the
    Epoch encoded as a value of type time_t. If the time since the Epoch
    cannot be represented, the function shall return the value
    (time_t)-1 and may set errno to indicate the error.

(unquote)

And a source code of error checking example as:

(quote)
    /* What day of the week is July 4, 2001? */

    #include <stdio.h>
    #include <time.h>

    struct tm time_str;

    char daybuf[20];

    int main(void)
    {
        time_str.tm_year = 2001 - 1900;
        time_str.tm_mon = 7 - 1;
        time_str.tm_mday = 4;
        time_str.tm_hour = 0;
        time_str.tm_min = 0;
        time_str.tm_sec = 1;
        time_str.tm_isdst = -1;
        if (mktime(&time_str) == -1) /* <-- HERE */
            (void)puts("-unknown-");
        else {
            (void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
            (void)puts(daybuf);
        }
        return 0;
    }

(unquote)

So I think the -1 return value of mktime should be properly handled.

Regards,
Kenji Rikitake














> 
> -- 
> Björn Gustavsson, Erlang/OTP, Ericsson AB
> 
> ________________________________________________________________
> erlang-patches (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-patches-unsubscribe@REDACTED


More information about the erlang-bugs mailing list