From aa568727d1206524f24ab7caf86b988760b1ef38 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Dec 2008 18:08:29 +0000 Subject: [PATCH] patch #6699: fixed some warnings on platform where sizeof(int) == 2 --- CHANGELOG | 3 +++ src/api/api_msg.c | 2 +- src/api/tcpip.c | 48 +++++++++++++++++++++++++++++++++---- src/core/ipv4/inet.c | 6 ++--- src/core/ipv4/inet_chksum.c | 2 +- src/core/tcp_in.c | 2 +- src/core/udp.c | 12 +++++----- src/include/lwip/tcp.h | 2 +- src/include/lwip/tcpip.h | 5 ++-- 9 files changed, 62 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 34b1baa2..97648f4f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -56,6 +56,9 @@ HISTORY ++ Bugfixes: + 2008-12-19 Simon Goldschmidt + * many files: patch #6699: fixed some warnings on platform where sizeof(int) == 2 + 2008-12-10 Tamas Somogyi, Frédéric Bernon * sockets.c: fixed bug #25051: lwip_recvfrom problem with udp: fromaddr and port uses deleted netbuf. diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 20c5fd89..ce4b5bcb 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -952,7 +952,7 @@ do_writemore(struct netconn *conn) LWIP_ASSERT("conn->state == NETCONN_WRITE", (conn->state == NETCONN_WRITE)); dataptr = (u8_t*)conn->write_msg->msg.w.dataptr + conn->write_offset; - if ((conn->write_msg->msg.w.len - conn->write_offset > 0xffff)) { /* max_u16_t */ + if ((conn->write_msg->msg.w.len - conn->write_offset > (int)0xffff)) { /* max_u16_t */ len = 0xffff; #if LWIP_TCPIP_CORE_LOCKING conn->write_delayed = 1; diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 29384b69..5fa4b958 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -297,11 +297,12 @@ tcpip_thread(void *arg) case TCPIP_MSG_TIMEOUT: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg)); - - if(msg->msg.tmo.msecs != 0xffffffff) - sys_timeout (msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg); - else - sys_untimeout (msg->msg.tmo.h, msg->msg.tmo.arg); + sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg); + memp_free(MEMP_TCPIP_MSG_API, msg); + break; + case TCPIP_MSG_UNTIMEOUT: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg)); + sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg); memp_free(MEMP_TCPIP_MSG_API, msg); break; @@ -379,6 +380,14 @@ tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block) return ERR_VAL; } +/** + * call sys_timeout in tcpip_thread + * + * @param msec time in miliseconds for timeout + * @param h function to be called on timeout + * @param arg argument to pass to timeout function h + * @return ERR_MEM on memory error, ERR_OK otherwise + */ err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg) { @@ -400,6 +409,35 @@ tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg) return ERR_VAL; } +/** + * call sys_untimeout in tcpip_thread + * + * @param msec time in miliseconds for timeout + * @param h function to be called on timeout + * @param arg argument to pass to timeout function h + * @return ERR_MEM on memory error, ERR_OK otherwise + */ +err_t +tcpip_untimeout(u32_t msecs, sys_timeout_handler h, void *arg) +{ + struct tcpip_msg *msg; + + if (mbox != SYS_MBOX_NULL) { + msg = memp_malloc(MEMP_TCPIP_MSG_API); + if (msg == NULL) { + return ERR_MEM; + } + + msg->type = TCPIP_MSG_UNTIMEOUT; + msg->msg.tmo.msecs = msecs; + msg->msg.tmo.h = h; + msg->msg.tmo.arg = arg; + sys_mbox_post(mbox, msg); + return ERR_OK; + } + return ERR_VAL; +} + #if LWIP_NETCONN /** * Call the lower part of a netconn_* function diff --git a/src/core/ipv4/inet.c b/src/core/ipv4/inet.c index 24c7ff46..496aabae 100644 --- a/src/core/ipv4/inet.c +++ b/src/core/ipv4/inet.c @@ -83,7 +83,8 @@ int inet_aton(const char *cp, struct in_addr *addr) { u32_t val; - int base, n, c; + u8_t base; + char c; u32_t parts[4]; u32_t *pp = parts; @@ -139,8 +140,7 @@ inet_aton(const char *cp, struct in_addr *addr) * Concoct the address according to * the number of parts specified. */ - n = pp - parts + 1; - switch (n) { + switch (pp - parts + 1) { case 0: return (0); /* initial nondigit */ diff --git a/src/core/ipv4/inet_chksum.c b/src/core/ipv4/inet_chksum.c index 9248f7d4..de7b49d1 100644 --- a/src/core/ipv4/inet_chksum.c +++ b/src/core/ipv4/inet_chksum.c @@ -107,7 +107,7 @@ lwip_standard_chksum(void *dataptr, u16_t len) } /* add deferred carry bits */ acc = (acc >> 16) + (acc & 0x0000ffffUL); - if ((acc & 0xffff0000) != 0) { + if ((acc & 0xffff0000UL) != 0) { acc = (acc >> 16) + (acc & 0x0000ffffUL); } /* This maybe a little confusing: reorder sum using htons() diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 765ac466..d58420c4 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -1316,7 +1316,7 @@ tcp_parseopt(struct tcp_pcb *pcb) /* Parse the TCP MSS option, if present. */ if(TCPH_HDRLEN(tcphdr) > 0x5) { - for(c = 0; c < (TCPH_HDRLEN(tcphdr) - 5) << 2 ;) { + for(c = 0; c < ((TCPH_HDRLEN(tcphdr) - 5) << 2) ;) { opt = opts[c]; if (opt == 0x00) { /* End of options. */ diff --git a/src/core/udp.c b/src/core/udp.c index 2f36c745..0d139b53 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -635,9 +635,9 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) } LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to %"U16_F".%"U16_F".%"U16_F".%"U16_F", port %"U16_F"\n", - (u16_t)(ntohl(pcb->local_ip.addr) >> 24 & 0xff), - (u16_t)(ntohl(pcb->local_ip.addr) >> 16 & 0xff), - (u16_t)(ntohl(pcb->local_ip.addr) >> 8 & 0xff), + (u16_t)((ntohl(pcb->local_ip.addr) >> 24) & 0xff), + (u16_t)((ntohl(pcb->local_ip.addr) >> 16) & 0xff), + (u16_t)((ntohl(pcb->local_ip.addr) >> 8) & 0xff), (u16_t)(ntohl(pcb->local_ip.addr) & 0xff), pcb->local_port)); return ERR_OK; } @@ -693,9 +693,9 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) #endif LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to %"U16_F".%"U16_F".%"U16_F".%"U16_F",port %"U16_F"\n", - (u16_t)(ntohl(pcb->remote_ip.addr) >> 24 & 0xff), - (u16_t)(ntohl(pcb->remote_ip.addr) >> 16 & 0xff), - (u16_t)(ntohl(pcb->remote_ip.addr) >> 8 & 0xff), + (u16_t)((ntohl(pcb->remote_ip.addr) >> 24) & 0xff), + (u16_t)((ntohl(pcb->remote_ip.addr) >> 16) & 0xff), + (u16_t)((ntohl(pcb->remote_ip.addr) >> 8) & 0xff), (u16_t)(ntohl(pcb->remote_ip.addr) & 0xff), pcb->remote_port)); /* Insert UDP PCB into the list of active UDP PCBs. */ diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index 883b0b83..35220b37 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -185,7 +185,7 @@ void tcp_rexmit_rto (struct tcp_pcb *pcb); #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */ #ifndef TCP_MSL -#define TCP_MSL 60000U /* The maximum segment lifetime in milliseconds */ +#define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */ #endif /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */ diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index 0d295641..4f5b7f8f 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -90,7 +90,7 @@ err_t pbuf_free_callback(struct pbuf *p); err_t mem_free_callback(void *m); err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); -#define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg) +err_t tcpip_untimeout(u32_t msecs, sys_timeout_handler h, void *arg); enum tcpip_msg_type { #if LWIP_NETCONN @@ -101,7 +101,8 @@ enum tcpip_msg_type { TCPIP_MSG_NETIFAPI, #endif /* LWIP_NETIF_API */ TCPIP_MSG_CALLBACK, - TCPIP_MSG_TIMEOUT + TCPIP_MSG_TIMEOUT, + TCPIP_MSG_UNTIMEOUT }; struct tcpip_msg {