[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [bug #25544] Warning in DHCP.H
From: |
David Empson |
Subject: |
[lwip-devel] [bug #25544] Warning in DHCP.H |
Date: |
Tue, 10 Feb 2009 22:32:51 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 |
Follow-up Comment #2, bug #25544 (project lwip):
The warning is valid.
In C, multiplying two values of type int will produce a result of type int.
If the expression is used in a context where a larger type is required, the
typecast to the larger type occurs after the multiplication.
In effect, this is calculating (u32_t)((int)60 * (int)1000).
On a 16-bit platform, the multiplication will overflow (because 60000 is
outside the range of int). The resulting negative value will then be converted
to a signed 32-bit integer, producing an enormous timeout.
I agree with Edward. At a minimum, the 1000 constant should be changed to
1000U, which will result in a 16-bit unsigned multiplication.
This still won't help if DHCP_COARSE_TIMER_SECS was ever set higher than 65,
because then you would get a 16-bit unsigned multiplication overflowing,
producing a result which was too small.
I suggest a better solution would be to use 1000UL, forcing the
multiplication to be calculated using 32-bit unsigned arithmetic.
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/bugs/?25544>
_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/