[PATCH] udhcpd: Handle auto_time timeout overflow

Cathey, Jim jcathey at ciena.com
Tue Jan 27 21:51:33 UTC 2015


At the bottom, some of C's arithmetical rules
are 'stupid'.  Especially as regards type
promotion.  At least they're well-defined.

Absolutely true in a mathematical sense is that
the difference between two unsigned numbers is
SIGNED!  But that's not what C does.  You can get
around this, easy enough, but you do have to
understand exactly what is going on.  It helps
if you are working on a 2's-complement machine.

Off the cuff, I think this works:

unsigned int a, b;
int delta;
...
delta = (int)a - (int)b;
if (delta < 0) delta = (int)b - (int)a;

-or maybe-

if (delta < 0) delta = -delta;

-- Jim



More information about the busybox mailing list