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

Submitted by:  Edward Harris <eharris>
Submitted on:  Tue 10 Feb 2009 02:06:25 PM UTC  
 
Category: IPv4Severity: 3 - Normal
Item Group: Compiler WarningStatus: Fixed
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned Release: None
lwIP version: 1.3.0

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

Fixed.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 11 Feb 2009 05:48:59 PM UTCgoldsimonStatusNone=>Fixed
      Assigned toNone=>goldsimon
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1