[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [bug #54850] lwip definition of htonX and ntohX do not prop
From: |
Ivan Warren |
Subject: |
[lwip-devel] [bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian |
Date: |
Wed, 17 Oct 2018 03:57:20 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 |
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] [bug #54850] lwip definition of htonX and ntohX do not properly cast to unsigned when byte order is Big Endian,
Ivan Warren <=