From ced2543be03f1d51eebfd93c6416e87e349b5b55 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 17 Jun 2007 14:39:50 +0000 Subject: [PATCH] Done some work on task #6933: converted some LWIP_ASSERTs to LWIP_ERROR to give back an error return value for LWIP_NOASSERT=1 --- src/api/sockets.c | 17 ++++++++++------- src/core/dhcp.c | 35 +++++++++++++++++++++++------------ src/core/memp.c | 2 +- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index 4f54dc9b..232bad12 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -251,8 +251,9 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen) if (!sock) return -1; - LWIP_ASSERT("lwip_bind: invalid address", (namelen == sizeof(struct sockaddr_in)) && - ((((struct sockaddr_in *)name)->sin_family) == AF_INET)); + LWIP_ERROR("lwip_bind: invalid address", ((namelen != sizeof(struct sockaddr_in)) || + ((((struct sockaddr_in *)name)->sin_family) != AF_INET)), + sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; local_port = ((struct sockaddr_in *)name)->sin_port; @@ -312,8 +313,9 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen) if (!sock) return -1; - LWIP_ASSERT("lwip_connect: invalid address", (namelen == sizeof(struct sockaddr_in)) && - ((((struct sockaddr_in *)name)->sin_family) == AF_INET)); + LWIP_ERROR("lwip_connect: invalid address", ((namelen != sizeof(struct sockaddr_in)) && + ((((struct sockaddr_in *)name)->sin_family) != AF_INET)), + sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) { LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s)); @@ -537,9 +539,10 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags, #endif /* LWIP_TCP */ } - LWIP_ASSERT("lwip_sendto: invalid address", (((to==NULL) && (tolen==0)) || - ((tolen == sizeof(struct sockaddr_in)) && - ((((struct sockaddr_in *)to)->sin_family) == AF_INET)))); + LWIP_ERROR("lwip_sendto: invalid address", (((to != NULL) || (tolen != 0)) && + ((tolen != sizeof(struct sockaddr_in)) || + ((((struct sockaddr_in *)to)->sin_family) != AF_INET))), + sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); #if LWIP_TCPIP_CORE_LOCKING /* Should only be consider like a sample or a simple way to experiment this option (no check of "to" field, no RAW send/sendto...) */ diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 09d7d3ab..4259c523 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -535,14 +535,15 @@ static void dhcp_handle_ack(struct netif *netif) */ err_t dhcp_start(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp; err_t result = ERR_OK; #if LWIP_DHCP_AUTOIP_COOP autoip_init(); #endif /* LWIP_DHCP_AUTOIP_COOP */ - LWIP_ASSERT("netif != NULL", netif != NULL); + LWIP_ERROR("netif == NULL", (netif == NULL), return ERR_ARG;); + dhcp = netif->dhcp; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); netif->flags &= ~NETIF_FLAG_DHCP; @@ -653,12 +654,12 @@ void dhcp_inform(struct netif *netif) /** * Match an ARP reply with the offered IP address. * + * @param netif the network interface on which the reply was received * @param addr The IP address we received a reply from - * */ void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr) { - LWIP_ASSERT("netif != NULL", netif != NULL); + LWIP_ERROR("netif == NULL", (netif == NULL), return;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_arp_reply()\n")); /* is a DHCP client doing an ARP check? */ if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { @@ -792,10 +793,11 @@ static err_t dhcp_discover(struct netif *netif) static void dhcp_bind(struct netif *netif) { u32_t timeout; - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp; struct ip_addr sn_mask, gw_addr; - LWIP_ASSERT("dhcp_bind: netif != NULL", netif != NULL); - LWIP_ASSERT("dhcp_bind: dhcp != NULL", dhcp != NULL); + LWIP_ERROR("dhcp_bind: netif == NULL", (netif == NULL), return;); + dhcp = netif->dhcp; + LWIP_ERROR("dhcp_bind: dhcp == NULL", (dhcp == NULL), return;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); /* temporary DHCP lease? */ @@ -1027,7 +1029,7 @@ err_t dhcp_release(struct netif *netif) void dhcp_stop(struct netif *netif) { struct dhcp *dhcp = netif->dhcp; - LWIP_ASSERT("dhcp_stop: netif != NULL", netif != NULL); + LWIP_ERROR("dhcp_stop: netif == NULL", (netif == NULL), return;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_stop()\n")); /* netif is DHCP configured? */ @@ -1113,11 +1115,13 @@ static void dhcp_option_long(struct dhcp *dhcp, u32_t value) */ static err_t dhcp_unfold_reply(struct dhcp *dhcp) { - struct pbuf *p = dhcp->p; + struct pbuf *p; u8_t *ptr; u16_t i; u16_t j = 0; - LWIP_ASSERT("dhcp->p != NULL", dhcp->p != NULL); + LWIP_ERROR("dhcp == NULL", (dhcp == NULL), return ERR_ARG;); + p = dhcp->p; + LWIP_ERROR("dhcp->p == NULL", (dhcp->p == NULL), return ERR_VAL;); /* free any left-overs from previous unfolds */ dhcp_free_reply(dhcp); /* options present? */ @@ -1299,8 +1303,11 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_ static err_t dhcp_create_request(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp; u16_t i; + LWIP_ERROR("dhcp_create_request: netif == NULL", (netif == NULL), return ERR_ARG;); + dhcp = netif->dhcp; + LWIP_ERROR("dhcp_create_request: dhcp == NULL", (dhcp == NULL), return ERR_VAL;); LWIP_ASSERT("dhcp_create_request: dhcp->p_out == NULL", dhcp->p_out == NULL); LWIP_ASSERT("dhcp_create_request: dhcp->msg_out == NULL", dhcp->msg_out == NULL); dhcp->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM); @@ -1343,7 +1350,10 @@ static err_t dhcp_create_request(struct netif *netif) static void dhcp_delete_request(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp; + LWIP_ERROR("dhcp_create_request: netif == NULL", (netif == NULL), return;); + dhcp = netif->dhcp; + LWIP_ERROR("dhcp_create_request: dhcp == NULL", (dhcp == NULL), return;); LWIP_ASSERT("dhcp_free_msg: dhcp->p_out != NULL", dhcp->p_out != NULL); LWIP_ASSERT("dhcp_free_msg: dhcp->msg_out != NULL", dhcp->msg_out != NULL); pbuf_free(dhcp->p_out); @@ -1360,6 +1370,7 @@ static void dhcp_delete_request(struct netif *netif) static void dhcp_option_trailer(struct dhcp *dhcp) { + LWIP_ERROR("dhcp_create_request: dhcp == NULL", (dhcp == NULL), return;); LWIP_ASSERT("dhcp_option_trailer: dhcp->msg_out != NULL\n", dhcp->msg_out != NULL); LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_len < DHCP_OPTIONS_LEN); dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END; diff --git a/src/core/memp.c b/src/core/memp.c index db6c7b2d..2edf2425 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -304,7 +304,7 @@ memp_malloc(memp_t type) struct memp *memp; SYS_ARCH_DECL_PROTECT(old_level); - LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX); + LWIP_ERROR("memp_malloc: type >= MEMP_MAX", (type >= MEMP_MAX), return NULL;); SYS_ARCH_PROTECT(old_level); #if MEMP_OVERFLOW_CHECK >= 2