INN timer code and time overflows

Russ Allbery rra at stanford.edu
Tue Oct 3 05:32:50 UTC 2000


Hm.  Could someone remind me how unsigned arithmetic works?

I'm looking at the innd timer code and I think the timer values wrap in a
long-running server.  gettime returns the number of milliseconds since the
first time it was called (at the start of the lifetime of innd), and it's
an unsigned int (32 bytes on most platforms).  That means the maximum
timestamp it can return is 4294967295, or 4294967 seconds, which is about
50 days.  After that point, I think the arithmetic would overflow.

Does this just quietly work anyway?  If you subtract a very high unsigned
number from a very low unsigned number, does it give you the right
difference?  I can't quite wrap my mind around it.

-- 
Russ Allbery (rra at stanford.edu)             <http://www.eyrie.org/~eagle/>



More information about the inn-workers mailing list