[tz] source code question regarding localtime.c PS

Arthur David Olson arthurdavidolson at gmail.com
Wed Aug 7 17:02:11 UTC 2013


 > Of course, there's no requirement that time_t values map to times in a
linear manner...

From...
    http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html
...we have:
    time_t: Used for time in seconds.

    @dashdashado


On Wed, Aug 7, 2013 at 12:51 PM, Clive D.W. Feather <clive at davros.org>wrote:

> Paul Eggert said:
> > Thanks for mentioning the problem.  The code relies on undefined
> > behavior when a time_t value is outside int_fast64_t range.
> > It's better to avoid undefined behavior,
>
> > +     if (!TYPE_INTEGRAL(time_t)) {
> > +             if (INTMAX_MIN < t && t < INTMAX_MAX) {
>
> In principle UINTMAX_MAX could be larger than the largest value
> representable in time_t if it is (say) float. If so, the implicit
> conversion to float is undefined and you haven't solved the problem. You
> need to compare the various limits to decide which type can handle all the
> values of the other.
>
> Of course, there's no requirement that time_t values map to times in a
> linear manner - for example, an integral time_t could be split into bit
> fields holding hours, minutes, seconds, etc. That's why difftime() exists.
>
> --
> Clive D.W. Feather          | If you lie to the compiler,
> Email: clive at davros.org     | it will get its revenge.
> Web: http://www.davros.org  |   - Henry Spencer
> Mobile: +44 7973 377646
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mm.icann.org/pipermail/tz/attachments/20130807/3b744d97/attachment.htm>


More information about the tz mailing list