bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #23996] arithmetic overflow when using -used


From: Andreas Schwab
Subject: Re: [bug #23996] arithmetic overflow when using -used
Date: Sun, 24 Aug 2008 01:01:17 +0200
User-agent: Gnus/5.110009 (No Gnus v0.9) Emacs/22.2 (gnu/linux)

James Youngman <address@hidden> writes:

> +       assert (nanosec < nanosec_per_sec);
> +
> +       /* Perform the subtraction, and then check for overflow. 
> +        * On systems where signed aritmetic overflow does not 
> +        * wrap, this check may be unreliable.   The C standard 
> +        * does not require this approach to work, but I am aware 
> +        * of no platforms where it fails.
> +        */
>         result->ts.tv_sec  = origin.tv_sec - seconds;
> +       if ((origin.tv_sec < result->ts.tv_sec) != (seconds < 0))

A good compiler (like gcc 4.3) will optimize this to 0, effectively
removing the overflow check.  Checking for overflow after the fact is
not possible in C.

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]