buglwIP - A Lightweight TCP/IP stack - Bugs: bug #25544, Warning in DHCP.H

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #25544: Warning in DHCP.H

Submitter:  Edward Harris <eharris>
Submitted:  Tue 10 Feb 2009 02:06:25 PM UTC
   
 
Category:  IPv4 Severity:  3 - Normal
Item Group:  Compiler Warning Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  1.3.0

Wed 11 Feb 2009 05:48:59 PM UTC, comment #5: 

Fixed.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 11 Feb 2009 10:01:59 AM UTC, comment #4: 

That great, thanks.

The platform is a GCC V4.2.4 port for the Cyan eCOG1X.

Edward Harris <eharris>
Wed 11 Feb 2009 07:03:45 AM UTC, comment #3: 

OK, my fault, should have known that.

> I suggest a better solution would be to use 1000UL


I thoguht so, too, while reading your post. I'll change it first thing when I get home ;-)

Simon Goldschmidt <goldsimon>
Group administrator
Tue 10 Feb 2009 10:32:51 PM UTC, comment #2: 

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.

David Empson <dempson>
Tue 10 Feb 2009 09:06:41 PM UTC, comment #1: 

Isn't this invalid: the only place where DHCP_COARSE_TIMER_MSECS is used is in a place where it is used as u32_t. Doesn't the compiler cast this to the correct type before evaluating the expression?

Which compiler are you using (and on which platform - I suppose a 16-bit one)?

Simon Goldschmidt <goldsimon>
Group administrator
Tue 10 Feb 2009 02:06:25 PM UTC, original submission:  

The line:

#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS*1000)

causes a warning to by generated from the compiler as the result overflows the default int type. Appending a U to the 1000 fixes this.

Edward Harris <eharris>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dempson (Posted a comment)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by eharris (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-02-11 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code