lwip corrected coverity and compiler warnings

Coverity ids: 1373147 and 1374442.
pull/4463/head
Mika Leppänen 2017-05-05 08:46:45 +03:00 committed by adbridge
parent 6b071dcf97
commit 4c4d0fa1e3
2 changed files with 14 additions and 3 deletions

View File

@ -27,9 +27,14 @@ EthernetInterface::EthernetInterface()
nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{ {
_dhcp = false; _dhcp = false;
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address)); strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
_ip_address[sizeof(_ip_address) - 1] = '\0';
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask)); strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
_netmask[sizeof(_netmask) - 1] = '\0';
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway)); strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
_gateway[sizeof(_gateway) - 1] = '\0';
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }

View File

@ -109,7 +109,9 @@ static void mbed_lwip_socket_callback(struct netconn *nc, enum netconn_evt eh, u
/* TCP/IP and Network Interface Initialisation */ /* TCP/IP and Network Interface Initialisation */
static struct netif lwip_netif; static struct netif lwip_netif;
#if LWIP_IPV4
static bool lwip_dhcp = false; static bool lwip_dhcp = false;
#endif
static char lwip_mac_address[NSAPI_MAC_SIZE]; static char lwip_mac_address[NSAPI_MAC_SIZE];
#if !LWIP_IPV4 || !LWIP_IPV6 #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)
return true; return true;
} }
#endif #endif
#if LWIP_IPV6 && LWIP_IPV4
return false; return false;
#endif
} }
static const ip_addr_t *mbed_lwip_get_ipv4_addr(const struct netif *netif) 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)
static void mbed_lwip_set_mac_address(void) static void mbed_lwip_set_mac_address(void)
{ {
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE) #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x", (void) snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x",
MBED_MAC_ADDR_0, MBED_MAC_ADDR_1, MBED_MAC_ADDR_2, MBED_MAC_ADDR_0, MBED_MAC_ADDR_1, MBED_MAC_ADDR_2,
MBED_MAC_ADDR_3, MBED_MAC_ADDR_4, MBED_MAC_ADDR_5); MBED_MAC_ADDR_3, MBED_MAC_ADDR_4, MBED_MAC_ADDR_5);
#else #else
char mac[6]; char mac[6];
mbed_mac_address(mac); mbed_mac_address(mac);
snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x", (void) snprintf(lwip_mac_address, NSAPI_MAC_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
#endif #endif
@ -366,7 +370,9 @@ char *mbed_lwip_get_ip_address(char *buf, nsapi_size_t buflen)
return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen); return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen);
} }
#endif #endif
#if LWIP_IPV6 && LWIP_IPV4
return NULL; return NULL;
#endif
} }
const char *mbed_lwip_get_netmask(char *buf, nsapi_size_t buflen) 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
return NSAPI_ERROR_NO_SOCKET; return NSAPI_ERROR_NO_SOCKET;
} }
u8_t lwip_proto = proto == NSAPI_TCP ? NETCONN_TCP : NETCONN_UDP; enum netconn_type lwip_proto = proto == NSAPI_TCP ? NETCONN_TCP : NETCONN_UDP;
#if LWIP_IPV6 && LWIP_IPV4 #if LWIP_IPV6 && LWIP_IPV4
const ip_addr_t *ip_addr; const ip_addr_t *ip_addr;