From 46b7bd6ec329854b1e688f987cff60674f64120f Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 26 Mar 2010 14:07:05 +0000 Subject: [PATCH] Make functions static where applicable, add default cases to switches where applicable, prevent old-style function prototypes (without arguments) --- src/api/api_msg.c | 5 ++++- src/api/sockets.c | 37 ++++++++++++++++++++++++++++++++++--- src/core/ipv4/ip_addr.c | 18 +++++++++++++----- src/core/stats.c | 4 ++-- src/include/lwip/stats.h | 6 +++--- 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 4e11684f..823ae4b8 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -653,7 +653,7 @@ netconn_free(struct netconn *conn) * @bytes_drained bytes drained from recvmbox * @accepts_drained pending connections drained from acceptmbox */ -void +static void netconn_drain(struct netconn *conn) { void *mem; @@ -1343,6 +1343,9 @@ do_getaddr(struct api_msg_msg *msg) *(msg->msg.ad.port) = (msg->msg.ad.local?msg->conn->pcb.tcp->local_port:msg->conn->pcb.tcp->remote_port); break; #endif /* LWIP_TCP */ + default: + LWIP_ASSERT("invalid netconn_type", 0); + break; } } else { msg->err = ERR_CONN; diff --git a/src/api/sockets.c b/src/api/sockets.c index 1d0524e3..386d5d7e 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1574,7 +1574,7 @@ lwip_getsockopt_internal(void *arg) optval = data->optval; switch (level) { - + /* Level: SOL_SOCKET */ case SOL_SOCKET: switch (optname) { @@ -1643,6 +1643,9 @@ lwip_getsockopt_internal(void *arg) *(int*)optval = (udp_flags(sock->conn->pcb.udp) & UDP_FLAGS_NOCHKSUM) ? 1 : 0; break; #endif /* LWIP_UDP*/ + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; @@ -1671,6 +1674,9 @@ lwip_getsockopt_internal(void *arg) s, *(u32_t *)optval)); break; #endif /* LWIP_IGMP */ + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; @@ -1706,7 +1712,9 @@ lwip_getsockopt_internal(void *arg) s, *(int *)optval)); break; #endif /* LWIP_TCP_KEEPALIVE */ - + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; #endif /* LWIP_TCP */ @@ -1724,9 +1732,15 @@ lwip_getsockopt_internal(void *arg) LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) = %d\n", s, (*(int*)optval)) ); break; + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; #endif /* LWIP_UDP */ + default: + LWIP_ASSERT("unhandled level", 0); + break; } /* switch (level) */ sys_sem_signal(&sock->conn->op_completed); } @@ -1993,6 +2007,9 @@ lwip_setsockopt_internal(void *arg) } break; #endif /* LWIP_UDP */ + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; @@ -2036,6 +2053,9 @@ lwip_setsockopt_internal(void *arg) } break; #endif /* LWIP_IGMP */ + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; @@ -2075,7 +2095,9 @@ lwip_setsockopt_internal(void *arg) s, sock->conn->pcb.tcp->keep_cnt)); break; #endif /* LWIP_TCP_KEEPALIVE */ - + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; #endif /* LWIP_TCP*/ @@ -2103,9 +2125,15 @@ lwip_setsockopt_internal(void *arg) LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) -> %d\n", s, (*(int*)optval)) ); break; + default: + LWIP_ASSERT("unhandled optname", 0); + break; } /* switch (optname) */ break; #endif /* LWIP_UDP */ + default: + LWIP_ASSERT("unhandled level", 0); + break; } /* switch (level) */ sys_sem_signal(&sock->conn->op_completed); } @@ -2193,6 +2221,9 @@ lwip_fcntl(int s, int cmd, int val) ret = 0; } break; + default: + LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_fcntl(%d, UNIMPL: %d, %d)\n", s, cmd, val)); + break; } return ret; } diff --git a/src/core/ipv4/ip_addr.c b/src/core/ipv4/ip_addr.c index c4bcdf73..68a482a1 100644 --- a/src/core/ipv4/ip_addr.c +++ b/src/core/ipv4/ip_addr.c @@ -163,8 +163,9 @@ ipaddr_aton(const char *cp, ip_addr_t *addr) * a.b.c (with c treated as 16 bits) * a.b (with b treated as 24 bits) */ - if (pp >= parts + 3) + if (pp >= parts + 3) { return (0); + } *pp++ = val; c = *++cp; } else @@ -173,8 +174,9 @@ ipaddr_aton(const char *cp, ip_addr_t *addr) /* * Check for trailing characters. */ - if (c != '\0' && !isspace(c)) + if (c != '\0' && !isspace(c)) { return (0); + } /* * Concoct the address according to * the number of parts specified. @@ -188,22 +190,28 @@ ipaddr_aton(const char *cp, ip_addr_t *addr) break; case 2: /* a.b -- 8.24 bits */ - if (val > 0xffffffUL) + if (val > 0xffffffUL) { return (0); + } val |= parts[0] << 24; break; case 3: /* a.b.c -- 8.8.16 bits */ - if (val > 0xffff) + if (val > 0xffff) { return (0); + } val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if (val > 0xff) + if (val > 0xff) { return (0); + } val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; + default: + LWIP_ASSERT("unhandled", 0); + break; } if (addr) { ip4_addr_set_u32(addr, htonl(val)); diff --git a/src/core/stats.c b/src/core/stats.c index bd252724..69f97d41 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -48,11 +48,11 @@ struct stats_ lwip_stats; -void stats_init() +void stats_init(void) { #ifdef LWIP_DEBUG #if MEMP_STATS - char * memp_names[] = { + const char * memp_names[] = { #define LWIP_MEMPOOL(name,num,size,desc) desc, #include "lwip/memp_std.h" }; diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index d82e1810..015b7ce7 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -148,7 +148,7 @@ struct stats_ { extern struct stats_ lwip_stats; -void stats_init(); +void stats_init(void); #define STATS_INC(x) ++lwip_stats.x #define STATS_DEC(x) --lwip_stats.x @@ -157,7 +157,7 @@ void stats_init(); lwip_stats.x.max = lwip_stats.x.used; \ } \ } while(0) -#else +#else /* LWIP_STATS */ #define stats_init() #define STATS_INC(x) #define STATS_DEC(x) @@ -276,7 +276,7 @@ void stats_display_igmp(struct stats_igmp *igmp); void stats_display_mem(struct stats_mem *mem, char *name); void stats_display_memp(struct stats_mem *mem, int index); void stats_display_sys(struct stats_sys *sys); -#else +#else /* LWIP_STATS_DISPLAY */ #define stats_display() #define stats_display_proto(proto, name) #define stats_display_igmp(igmp)