zdump loop problem
Clive D.W. Feather
clive at demon.net
Tue Nov 25 09:26:03 UTC 2008
Paul Eggert said:
> Also, the code is overly complicated. I suggest using
> something like this instead:
> if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12)
> newt = t + SECSPERHOUR * 12;
> The seemingly redundant "t >= cuthitime" test prevents arithmetic
> overflow in the subtraction (admittedly highly unlikely, but I couldn't
> prove to my own satisfaction that it could never occur).
On a system with 2-byte integers, SECSPERHOUR * 12 will overflow. This can
be fixed by changing the 12 to 12L.
Apart from that, the overflow can only occur if cuthitime is extremely
negative (within 43,200 of the most negative value). I don't have the code
to hand and Google only points me at a Hungarian version, so I can't check
if that can ever happen.
Incidentally, does setabsolutes() have the same problem in it?
Clive D.W. Feather | Work: <clive at demon.net> | Tel: +44 20 8495 6138
Internet Expert | Home: <clive at davros.org> | Fax: +44 870 051 9937
Demon Internet | WWW: http://www.davros.org | Mobile: +44 7973 377646
THUS - a Cable and Wireless business
More information about the tz