proposed time zone package changes (revised)

Jonathan Leffler jonathan.leffler at gmail.com
Sat Feb 6 19:59:21 UTC 2010


On Sat, Feb 6, 2010 at 11:49 AM, Arthur David Olson <
olsona at elsie.nci.nih.gov> wrote:

> Here are the proposed changes, revised to incorporate KRE's suggestion
> on how to handle NULLs passed to asctime_r.
>
>                                --ado
>
> ------- asctime.c -------
> *** /tmp/geta27327      Sat Feb  6 14:46:35 2010
> --- /tmp/getb27327      Sat Feb  6 14:46:35 2010
> [...]
>
> ***************
> *** 91,96 ****
> --- 91,101 ----
>        char                    year[INT_STRLEN_MAXIMUM(int) + 2];
>        char                    result[MAX_ASCTIME_BUF_SIZE];
>
> +       if (timeptr == NULL) {
> +               errno = EINVAL;
> +               (void) strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
> +               return buf;
> +       }
>        if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
>                wn = "???";
>        else    wn = wday_name[timeptr->tm_wday];
>


You could avoid the cast by using:

    return strcpy(buf, "??? ??? ?? ??:??:?? ????\n");

This is one of the few occasions when the return value from strcpy()
actually is useful.  (So often, it would be more useful if it returned a
pointer to the NUL '\0' at the end of the string.)




-- 
Jonathan Leffler <jonathan.leffler at gmail.com>  #include <disclaimer.h>
Guardian of DBD::Informix - v2008.0513 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm.icann.org/pipermail/tz/attachments/20100206/d1c05065/attachment-0001.html 


More information about the tz mailing list