buglwIP - A Lightweight TCP/IP stack - Bugs: bug #51538, Don't use signed types when...

 
 

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

bug #51538: Don't use signed types when overflow is expected

Submitter:  Daniel Elstner <danielk>
Submitted:  Sat 22 Jul 2017 02:02:14 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  Change Request Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  2.1.0
lwIP version:  git head

Fri 17 Nov 2017 08:39:42 PM UTC, comment #2: 


> Can you provide a change that works with -Wconversion?


Obviously not, thanks for the talk ;-)

Reverting the 2 lines in question, I don't have access to a compiler telling me about -Wconversion right now, and it's not that pressing anyway: there are enough files left that don't compile with this setting...

Simon Goldschmidt <goldsimon>
Group administrator
Mon 24 Jul 2017 06:27:48 PM UTC, comment #1: 

Hmm, while the part about the standard is true, I'm not aware of a system where this doesn't work and as such, I didn't pay much attention.

Can you provide a change that works with -Wconversion?

Simon Goldschmidt <goldsimon>
Group administrator
Sat 22 Jul 2017 02:02:14 PM UTC, original submission:  

I just noticed that commit f3c860958fbea544e9e1e4222339a1373dcbf3b6 "-Wconversion (still far from finished) and other minor compilation fixes..." changes some types from unsigned to signed.

Some of these are in code I wrote in sntp.c:


- #define DIFF_SEC_1970_2036          ((u32_t)2085978496L)
+ #define DIFF_SEC_1970_2036          ((s32_t)2085978496L)



- ut = (u32_t)((u32_t)sec + DIFF_SEC_1970_2036);
+ ut = (time_t)((time_t)sec + (time_t)DIFF_SEC_1970_2036);


The problem with these changes is that according to the C standard, any overflow resulting from calculations on signed integer types leads to undefined behavior. That is the reason why I put these convoluted casts to and from unsigned in the code; as for unsigned integer types the C standard defines modulo behavior in case of overflow.

The use of time_t in the calculations could also lead to wrong results due to sign extension on platforms where time_t is a signed 64-bit integer.

Daniel Elstner <danielk>

 

(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 goldsimon (Posted a comment)
  • -email is unavailable- added by danielk (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-11-17 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2017-11-17 goldsimon Planned ReleaseNone 2.1.0

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code