From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78476 invoked by alias); 18 Apr 2018 20:37:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 78459 invoked by uid 89); 18 Apr 2018 20:37:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,KAM_NUMSUBJECT,SPF_PASS autolearn=no version=3.3.2 spammy=Thatd, that'd, thatd, That'd X-HELO: zimbra.cs.ucla.edu Subject: Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 To: "Albert ARIBAUD (3ADEV)" , libc-alpha@sourceware.org References: <20180418201819.15952-1-albert.aribaud@3adev.fr> <20180418201819.15952-2-albert.aribaud@3adev.fr> <20180418201819.15952-3-albert.aribaud@3adev.fr> From: Paul Eggert Message-ID: <0a04fc43-9e92-1bbc-843d-049d1026d971@cs.ucla.edu> Date: Wed, 18 Apr 2018 20:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180418201819.15952-3-albert.aribaud@3adev.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2018-04/txt/msg00370.txt.bz2 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.