From de531131c54103543dcd95aeedfc99a8e95220a0 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Sat, 7 Oct 2017 21:45:43 -0500 Subject: [PATCH] Fix compiler warnings seen with clang 8.1.0 on MacOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the following warnings: test_tcp.c:266:5: error: code will never be executed [-Werror,-Wunreachable-code]     pbuf_free(p);     ^~~~~~~~~ - The check API 'fail' aborts the test, thus pbuf_free(p) will never be executed pbuf.c:783:111: error: format specifies type 'unsigned short' but the argument has type 'u8_t' (aka 'unsigned char') [-Werror,-Wformat]       LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, ref));       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ - LWIP_PBUF_REF_T is u8_t by default and doesn't match U16_F, so cast to u16_t. The cast and formatter will need to be changed if ref is larger than 16 bits ethernet.c:105:16: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]                (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2], ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - addr[] is type u8_t, formatter is X8_F which should be 8 bits. 'unsigned' is an int, so cast to unsighed char instead --- src/core/pbuf.c | 2 +- src/netif/ethernet.c | 8 ++++---- test/unit/tcp/test_tcp.c | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 0ecffd22..39ecda68 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -780,7 +780,7 @@ pbuf_free(struct pbuf *p) /* p->ref > 0, this pbuf is still referenced to */ /* (and so the remaining pbufs in chain as well) */ } else { - LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, ref)); + LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, (u16_t)ref)); /* stop walking through the chain */ p = NULL; } diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 3ac2fcef..56f72c8f 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -102,10 +102,10 @@ ethernet_input(struct pbuf *p, struct netif *netif) ethhdr = (struct eth_hdr *)p->payload; LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("ethernet_input: dest:%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F", src:%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F", type:%"X16_F"\n", - (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2], - (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5], - (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2], - (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5], + (unsigned char)ethhdr->dest.addr[0], (unsigned char)ethhdr->dest.addr[1], (unsigned char)ethhdr->dest.addr[2], + (unsigned char)ethhdr->dest.addr[3], (unsigned char)ethhdr->dest.addr[4], (unsigned char)ethhdr->dest.addr[5], + (unsigned char)ethhdr->src.addr[0], (unsigned char)ethhdr->src.addr[1], (unsigned char)ethhdr->src.addr[2], + (unsigned char)ethhdr->src.addr[3], (unsigned char)ethhdr->src.addr[4], (unsigned char)ethhdr->src.addr[5], lwip_htons(ethhdr->type))); type = ethhdr->type; diff --git a/test/unit/tcp/test_tcp.c b/test/unit/tcp/test_tcp.c index c272202c..ba89cd6d 100644 --- a/test/unit/tcp/test_tcp.c +++ b/test/unit/tcp/test_tcp.c @@ -263,7 +263,6 @@ test_tcp_recv_expectclose(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t if (p != NULL) { fail(); - pbuf_free(p); } else { /* correct: FIN received; close our end, too */ err_t err2 = tcp_close(pcb);