[[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time

Paul Eggert eggert@cs.ucla.edu
Thu Apr 19 01:02:00 GMT 2018


On 04/18/2018 01:17 PM, Albert ARIBAUD (3ADEV) wrote:
>   int
> -__offtime (const time_t *t, long int offset, struct tm *tp)
> +__offtime (const __time64_t t, long int offset, struct tm *tp)
>   {
>     time_t days, rem, y;
>     const unsigned short int *ip;
>   
> -  days = *t / SECS_PER_DAY;
> -  rem = *t % SECS_PER_DAY;
> +  days = t / SECS_PER_DAY;
> +  rem = t % SECS_PER_DAY;

This can overflow when time_t is 32 bits, because dividing a 64-bit 
integer by SECS_PER_DAY (i.e., by 86400) can yield an integer that does 
not fit into 32 bits. To fix this, you'll need to change the locals 
'days', 'y', 'yg' to be of type __time64_t rather than time_t.

Similarly, the local variable 't' in compute_change needs to be 
__time64_t, not time_t.

By the way, please add test cases to catch these bugs, and the bug I 
reported earlier today.

> -      tz_rules[0].change = tz_rules[1].change = (time_t) -1;
> +      tz_rules[0].change = tz_rules[1].change = (__time64_t) -1;
Instead, please just omit the cast; the cast is not needed and is more 
maintenance hassle than it is worth.



More information about the Libc-alpha mailing list