Skip to content

Commit 55753be

Browse files
author
Mika Leppänen
committed
lwip corrected coverity and compiler warnings
Coverity ids: 1373147 and 1374442.
1 parent 053139b commit 55753be

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

features/FEATURE_LWIP/lwip-interface/EthernetInterface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ EthernetInterface::EthernetInterface()
2727
nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
2828
{
2929
_dhcp = false;
30+
3031
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
32+
_ip_address[sizeof(_ip_address) - 1] = '\0';
3133
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
34+
_netmask[sizeof(_netmask) - 1] = '\0';
3235
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
36+
_gateway[sizeof(_gateway) - 1] = '\0';
37+
3338
return NSAPI_ERROR_OK;
3439
}
3540

features/FEATURE_LWIP/lwip-interface/lwip_stack.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ static void mbed_lwip_socket_callback(struct netconn *nc, enum netconn_evt eh, u
109109

110110
/* TCP/IP and Network Interface Initialisation */
111111
static struct netif lwip_netif;
112+
#if LWIP_IPV4
112113
static bool lwip_dhcp = false;
114+
#endif
113115
static char lwip_mac_address[NSAPI_MAC_SIZE];
114116

115117
#if !LWIP_IPV4 || !LWIP_IPV6
@@ -190,7 +192,9 @@ static bool convert_lwip_addr_to_mbed(nsapi_addr_t *out, const ip_addr_t *in)
190192
return true;
191193
}
192194
#endif
195+
#if LWIP_IPV6 && LWIP_IPV4
193196
return false;
197+
#endif
194198
}
195199

196200
static const ip_addr_t *mbed_lwip_get_ipv4_addr(const struct netif *netif)
@@ -325,13 +329,13 @@ static void mbed_lwip_netif_status_irq(struct netif *lwip_netif)
325329
static void mbed_lwip_set_mac_address(void)
326330
{
327331
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
328-
snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x",
332+
(void) snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x",
329333
MBED_MAC_ADDR_0, MBED_MAC_ADDR_1, MBED_MAC_ADDR_2,
330334
MBED_MAC_ADDR_3, MBED_MAC_ADDR_4, MBED_MAC_ADDR_5);
331335
#else
332336
char mac[6];
333337
mbed_mac_address(mac);
334-
snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x",
338+
(void) snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x",
335339
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
336340
#endif
337341

@@ -366,7 +370,9 @@ char *mbed_lwip_get_ip_address(char *buf, nsapi_size_t buflen)
366370
return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen);
367371
}
368372
#endif
373+
#if LWIP_IPV6 && LWIP_IPV4
369374
return NULL;
375+
#endif
370376
}
371377

372378
const char *mbed_lwip_get_netmask(char *buf, nsapi_size_t buflen)
@@ -676,7 +682,7 @@ static nsapi_error_t mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t
676682
return NSAPI_ERROR_NO_SOCKET;
677683
}
678684

679-
u8_t lwip_proto = proto == NSAPI_TCP ? NETCONN_TCP : NETCONN_UDP;
685+
enum netconn_type lwip_proto = proto == NSAPI_TCP ? NETCONN_TCP : NETCONN_UDP;
680686

681687
#if LWIP_IPV6 && LWIP_IPV4
682688
const ip_addr_t *ip_addr;

0 commit comments

Comments
 (0)