Fix a few -Wconversion warnings (there are many more to do)
diff --git a/src/core/def.c b/src/core/def.c
index bdece2f..70d3e58 100644
--- a/src/core/def.c
+++ b/src/core/def.c
@@ -101,7 +101,7 @@
lwip_strnstr(const char* buffer, const char* token, size_t n)
{
const char* p;
- int tokenlen = (int)strlen(token);
+ size_t tokenlen = strlen(token);
if (tokenlen == 0) {
return LWIP_CONST_CAST(char *, buffer);
}
diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c
index 6f5311d..e030ecc 100644
--- a/src/core/ipv4/icmp.c
+++ b/src/core/ipv4/icmp.c
@@ -81,7 +81,7 @@
#endif /* LWIP_DEBUG */
struct icmp_echo_hdr *iecho;
const struct ip_hdr *iphdr_in;
- s16_t hlen;
+ u16_t hlen;
const ip4_addr_t* src;
ICMP_STATS_INC(icmp.recv);
@@ -148,7 +148,7 @@
}
#endif
#if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
- if (pbuf_header(p, (hlen + PBUF_LINK_HLEN + PBUF_LINK_ENCAPSULATION_HLEN))) {
+ if (pbuf_header(p, (s16_t)(hlen + PBUF_LINK_HLEN + PBUF_LINK_ENCAPSULATION_HLEN))) {
/* p is not big enough to contain link headers
* allocate a new one and copy p into it
*/
@@ -167,7 +167,7 @@
/* copy the ip header */
MEMCPY(r->payload, iphdr_in, hlen);
/* switch r->payload back to icmp header (cannot fail) */
- if (pbuf_header(r, -hlen)) {
+ if (pbuf_header(r, (s16_t)-hlen)) {
LWIP_ASSERT("icmp_input: moving r->payload to icmp header failed\n", 0);
pbuf_free(r);
goto icmperr;
@@ -194,7 +194,7 @@
/* We generate an answer by switching the dest and src ip addresses,
* setting the icmp type to ECHO_RESPONSE and updating the checksum. */
iecho = (struct icmp_echo_hdr *)p->payload;
- if (pbuf_header(p, hlen)) {
+ if (pbuf_header(p, (s16_t)hlen)) {
LWIP_DEBUGF(ICMP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("Can't move over header in packet"));
} else {
err_t ret;
diff --git a/src/core/ipv4/ip4_addr.c b/src/core/ipv4/ip4_addr.c
index eb812af..2d47992 100644
--- a/src/core/ipv4/ip4_addr.c
+++ b/src/core/ipv4/ip4_addr.c
@@ -183,10 +183,10 @@
}
for (;;) {
if (isdigit(c)) {
- val = (val * base) + (int)(c - '0');
+ val = (val * base) + (u32_t)(c - '0');
c = *++cp;
} else if (base == 16 && isxdigit(c)) {
- val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
+ val = (val << 4) | (u32_t)(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp;
} else {
break;
@@ -310,7 +310,7 @@
do {
rem = *ap % (u8_t)10;
*ap /= (u8_t)10;
- inv[i++] = '0' + rem;
+ inv[i++] = (char)('0' + rem);
} while (*ap);
while (i--) {
if (len++ >= buflen) {
diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c
index f17b6c8..a542a86 100644
--- a/src/core/ipv6/ip6.c
+++ b/src/core/ipv6/ip6.c
@@ -715,7 +715,7 @@
options_done:
/* p points to IPv6 header again. */
- pbuf_header_force(p, ip_data.current_ip_header_tot_len);
+ pbuf_header_force(p, (s16_t)ip_data.current_ip_header_tot_len);
/* send to upper layers */
LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: \n"));
diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c
index 964291e..aa06659 100644
--- a/src/core/ipv6/ip6_addr.c
+++ b/src/core/ipv6/ip6_addr.c
@@ -132,8 +132,8 @@
} else if (isxdigit(*s)) {
/* add current digit */
current_block_value = (current_block_value << 4) +
- (isdigit(*s) ? *s - '0' :
- 10 + (islower(*s) ? *s - 'a' : *s - 'A'));
+ (isdigit(*s) ? (u32_t)(*s - '0') :
+ (u32_t)(10 + (islower(*s) ? *s - 'a' : *s - 'A')));
} else {
/* unexpected digit, space? CRLF? */
break;
diff --git a/src/core/netif.c b/src/core/netif.c
index f7211f9..1d3de0f 100644
--- a/src/core/netif.c
+++ b/src/core/netif.c
@@ -478,7 +478,7 @@
return NULL;
}
- num = name[2] - '0';
+ num = (u8_t)(name[2] - '0');
for (netif = netif_list; netif != NULL; netif = netif->next) {
if (num == netif->num &&
diff --git a/src/core/pbuf.c b/src/core/pbuf.c
index 52f088d..6047738 100644
--- a/src/core/pbuf.c
+++ b/src/core/pbuf.c
@@ -568,11 +568,11 @@
}
if (header_size_increment < 0) {
- increment_magnitude = -header_size_increment;
+ increment_magnitude = (u16_t)-header_size_increment;
/* Check that we aren't going to move off the end of the pbuf */
LWIP_ERROR("increment_magnitude <= p->len", (increment_magnitude <= p->len), return 1;);
} else {
- increment_magnitude = header_size_increment;
+ increment_magnitude = (u16_t)header_size_increment;
#if 0
/* Can't assert these as some callers speculatively call
pbuf_header() to see if it's OK. Will return 1 below instead. */
diff --git a/src/core/udp.c b/src/core/udp.c
index 52830c4..a916414 100644
--- a/src/core/udp.c
+++ b/src/core/udp.c
@@ -404,7 +404,7 @@
destination address was broadcast/multicast. */
if (!broadcast && !ip_addr_ismulticast(ip_current_dest_addr())) {
/* move payload pointer back to ip header */
- pbuf_header_force(p, ip_current_header_tot_len() + UDP_HLEN);
+ pbuf_header_force(p, (s16_t)(ip_current_header_tot_len() + UDP_HLEN));
icmp_port_unreach(ip_current_is_v6(), p);
}
#endif /* LWIP_ICMP || LWIP_ICMP6 */
diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
index 0965e09..174f9b7 100644
--- a/src/include/lwip/opt.h
+++ b/src/include/lwip/opt.h
@@ -1363,7 +1363,7 @@
* for an additional encapsulation header before ethernet headers (e.g. 802.11)
*/
#if !defined PBUF_LINK_ENCAPSULATION_HLEN || defined __DOXYGEN__
-#define PBUF_LINK_ENCAPSULATION_HLEN 0
+#define PBUF_LINK_ENCAPSULATION_HLEN 0u
#endif
/**
diff --git a/src/include/lwip/prot/tcp.h b/src/include/lwip/prot/tcp.h
index c2c03aa..67fe7b9 100644
--- a/src/include/lwip/prot/tcp.h
+++ b/src/include/lwip/prot/tcp.h
@@ -85,7 +85,7 @@
#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | TCPH_FLAGS(phdr))
#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | lwip_htons(flags))
-#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | (flags))
+#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = (u16_t)(lwip_htons((u16_t)((len) << 12) | (flags)))
#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | lwip_htons(flags))
#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~lwip_htons(flags))