[tz] source code question regarding localtime.c PS

Alois Treindl alois at astro.ch
Wed Aug 7 16:02:53 UTC 2013


thank you. I admit that I tend to overlook the problems arising from
portability to unusual machines.

More source code comments would be useful, as such code is not obvious.

On 07.08.13 16:27, Clive D.W. Feather wrote:
> Alois Treindl said:
>> In localtime.c, function localsub() are these three lines of code:
>>
>> 1295    icycles = tcycles;
>> 1296    if (tcycles - icycles >= 1 || icycles - tcycles >=  1)
>> 1297      return NULL;
>>
>> I do not understand the reason why lines 1296 and 1297 exist.
>> icycles and tcycles are equal.
>
> time_t just has to be an arithmetic type. This could include long long,
> double, long double, or even a complex type. Therefore it's possible that
> tcycles could contain a value that's not in the range of int_fast64_t
> (the type of icycles).
>
> That code checks whether the value in tcycles is within the range of
> int_fast64_t. If it is, the conversion on line 1295 will either produce the
> same number or (if time_t is floating point) will round it off to the
> nearest integer. In that case, both halves of the test will be false.
>
> But if the value in tcycles is out of range, the conversion will generate a
> completely different number, and so one of those tests will be true.
>


More information about the tz mailing list