lwip-devel
[Top][All Lists]
Advanced

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

Re: [lwip-devel] [patch #6699] Fixing a couple of compilation warnings(P


From: Alain M.
Subject: Re: [lwip-devel] [patch #6699] Fixing a couple of compilation warnings(Paradigm C++)
Date: Fri, 19 Dec 2008 19:46:46 -0200
User-agent: Thunderbird 2.0.0.17 (X11/20080914)

Why not use MAX_UINT? it should work on every compyler.

Alain

Mike Kleshov escreveu:
Follow-up Comment #3, patch #6699 (project lwip):

Hi,
I am concerned by this change in api_msg.c:

@@ -955 +955 @@
-  if ((conn->write_msg->msg.w.len - conn->write_offset > 0xffff)) { /*
max_u16_t */
+  if ((conn->write_msg->msg.w.len - conn->write_offset > (int)0xffff)) { /*
max_u16_t */

Short version:
It might silence the warning with this particular compiler but it keeps the
bug in the code in case of sizeof(int)==2.

Long version:
The code should work fine if sizeof(int)==4. Let's consider the case of
sizeof(int)==2.
In the original version of the code, the integer constant 0xffff has the type
unsigned int which is u16_t. The left side of operator < will be converted to
u16_t. The unsigned comparison will be pointless (always false.)
In the changed version of the code, the integer constant 0xffff is converted
to int and becomes -1. The signed comparison will be pointless as well (always
true.)
To fix the bug, we need to change the types of both
conn->write_msg->msg.w.len and conn->write_offset. Obviously, the piece of
code in question assumes that both of them are at least s32_t. At the moment
they are int (s16_t).

Other thoughts:
1) In general, I would oppose changes to the code that only intend to silence
questionable warnings of some particular compiler.
2) Why the double parentheses around the condition in this if statement?

- mike

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/patch/?6699>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-devel






reply via email to

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