James Youngman <[EMAIL PROTECTED]> 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, [EMAIL PROTECTED]
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