[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #33398] Compiler says 'Pointless Comparison'

From: David Empson
Subject: [lwip-devel] [bug #33398] Compiler says 'Pointless Comparison'
Date: Wed, 25 May 2011 22:53:21 +0000
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

Follow-up Comment #3, bug #33398 (project lwip):

Sounds like a compiler bug to me. If the compiler's int is 32 bits, 0xFFFF
should be treated as a 32-bit signed integer (0x0000FFFF), and u16_t port
would be converted to a 32-bit signed integer for the comparison. If port was
in the range 0x0000 to 0xFFFE before the increment it would be less than
0x0000FFFF, so the comparison is not always true.

I suspect the compiler is sign extending the 0xFFFF constant in that
expression instead of zero extending it. That would result in a comparison
testing whether a variable in the range 0x00000000 to 0x0000FFFF is greater
than or equal to -1, which is always true. This is clearly a bug. I suggest
reporting it to IAR, as it may crop up in other circumstances.

(port++ > 0xFFFF) is being handled correctly, so the bug appears to be limited
to the greater-than-or-equal operator. Hopefully changing the comparison to ==
will avoid the bug. 

Other (correctly implemented) compilers would not warn about the comparison,
since it is valid (although the greater-than portion of the comparison is


Reply to this item at:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]