This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Hi Paul,

On Wed, 18 Apr 2018 13:37:41 -0700, Paul Eggert <eggert@cs.ucla.edu>
wrote :

> 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.

Correct -- I'll fix this (and add the tests to cover the overflow
cases).

> 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.

One reason to have a separated implementation is that difftime.c has
quite complex logic covering many different implementations of time_t
(signed, unsigned, with padding bits) whereas here we only have signed
64-bit integer.

Cordialement,
Albert ARIBAUD
3ADEV


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]