[[PATCH RFC 2] 02/63] Y2038: add function __difftime64

Paul Eggert eggert@cs.ucla.edu
Wed Apr 18 20:37:00 GMT 2018


On 04/18/2018 01:17 PM, Albert ARIBAUD (3ADEV) wrote:
> +/* Return the difference between 64-bit TIME1 and TIME0.  */
> +double
> +__difftime64 (__time64_t time1, __time64_t time0)
> +{
> +  /* Subtract the smaller integer from the larger, convert the difference to
> +     double, and then negate if needed.  */
> +  return time1 < time0 ? - (time0 - time1) : (time1 - time0);
> +}

This does not work correctly if there is an integer overflow in any of 
the three subtractions. Also, the comment disagrees with the code.

How about if you just #include difftime.c after defining a couple of 
macros, and then have difftime.c do its thing? That'd avoid problems 
like this. difftime.c would also need to be generalized a bit.



More information about the Libc-alpha mailing list