[bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian

Simon Goldschmidt
URL:
  <https://savannah.nongnu.org/bugs/?54850>

                 Summary: lwip definition of htonX and ntohX do not properly
cast to unsigned when byte order is Big Endian
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: ivanw
            Submitted on: Wed 17 Oct 2018 07:57:18 AM UTC
                Category: Platform ports
                Severity: 3 - Normal
              Item Group: Compiler Warning
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: 2.1.0

    _______________________________________________________

Details:

in src/include/lwip/def.h the definitions for
- lwip_ntohl
- lwip_htonl
- lwip_ntohs
- lwip_htons

on big endian systems are defined as : #define lwip_xxx(x) (x)

However, this leads to compiler warning/errors sign compares if 'x' is signed
since the result is expected to be an unsigned value (even if x is a signed
scalar).

Fixed with the following patch :

diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h
index 3d6e107e..200af1c3 100644
--- a/src/include/lwip/def.h
+++ b/src/include/lwip/def.h
@@ -83,14 +83,14 @@ extern "C" {
 #endif

 #if BYTE_ORDER == BIG_ENDIAN
-#define lwip_htons(x) (x)
-#define lwip_ntohs(x) (x)
-#define lwip_htonl(x) (x)
-#define lwip_ntohl(x) (x)
-#define PP_HTONS(x) (x)
-#define PP_NTOHS(x) (x)
-#define PP_HTONL(x) (x)
-#define PP_NTOHL(x) (x)
+#define lwip_htons(x) (u16_t)(x)
+#define lwip_ntohs(x) (u16_t)(x)
+#define lwip_htonl(x) (u32_t)(x)
+#define lwip_ntohl(x) (u32_t)(x)
+#define PP_HTONS(x) (u16_t)(x)
+#define PP_NTOHS(x) (u16_t)(x)
+#define PP_HTONL(x) (u32_t)(x)
+#define PP_NTOHL(x) (u32_t)(x)
 #else /* BYTE_ORDER != BIG_ENDIAN */
 #ifndef lwip_htons
 u16_t lwip_htons(u16_t x);





    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?54850>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian

Simon Goldschmidt
Update of bug #54850 (project lwip):

                  Status:                    None => Fixed                  
             Open/Closed:                    Open => Closed                

    _______________________________________________________

Follow-up Comment #1:

Fixed, thanks for reporting!

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?54850>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian

Simon Goldschmidt
Follow-up Comment #2, bug #54850 (project lwip):

In the days of even ARM processors being little endian, big endian systems are
not used that often any more (which is odd at least for networking systems).

Being like that, please don't hesitate to inform us of any other glitches you
observe on your big endian platform :-)

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?54850>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian

Simon Goldschmidt
Follow-up Comment #3, bug #54850 (project lwip):

Thanks Simon & Dirk.

Note that my current project is just a hobby retro computing project (Having
an IP stack on VM/370 under hercules). So any bug I file will always be low
priority (and I will always attempt to submit a solution)

--Ivan

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?54850>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel