From f3c860958fbea544e9e1e4222339a1373dcbf3b6 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 6 Jul 2017 22:47:11 +0200 Subject: [PATCH] -Wconversion (still far from finished) and other minor compilation fixes... --- src/apps/httpd/httpd.c | 4 +-- src/apps/smtp/smtp.c | 54 ++++++++++++++++++------------ src/apps/snmp/snmp_core.c | 9 +++-- src/apps/sntp/sntp.c | 13 +++---- src/core/tcp_in.c | 53 +++++++++++++++++------------ src/core/tcp_out.c | 6 ++-- src/include/lwip/apps/httpd_opts.h | 2 +- src/include/lwip/priv/tcp_priv.h | 2 +- src/include/lwip/sockets.h | 6 ++-- src/include/lwip/tcp.h | 6 ++-- 10 files changed, 89 insertions(+), 66 deletions(-) diff --git a/src/apps/httpd/httpd.c b/src/apps/httpd/httpd.c index f3eff12c..f8d2233f 100644 --- a/src/apps/httpd/httpd.c +++ b/src/apps/httpd/httpd.c @@ -2269,7 +2269,7 @@ http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const cha } else #endif /* LWIP_HTTPD_CUSTOM_FILES */ { - hs->left = file->len; + hs->left = (u32_t)file->len; } hs->retries = 0; #if LWIP_HTTPD_TIMING @@ -2285,7 +2285,7 @@ http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const cha search for the end of the header. */ char *file_start = lwip_strnstr(hs->file, CRLF CRLF, hs->left); if (file_start != NULL) { - size_t diff = file_start + 4 - hs->file; + int diff = file_start + 4 - hs->file; hs->file += diff; hs->left -= (u32_t)diff; } diff --git a/src/apps/smtp/smtp.c b/src/apps/smtp/smtp.c index a62a3499..199b07a6 100644 --- a/src/apps/smtp/smtp.c +++ b/src/apps/smtp/smtp.c @@ -886,7 +886,7 @@ smtp_dns_found(const char* hostname, const ip_addr_t *ipaddr, void *arg) #if SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN /** Table 6-bit-index-to-ASCII used for base64-encoding */ -static const u8_t base64_table[] = { +static const char base64_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', @@ -914,10 +914,11 @@ smtp_base64_encode(char* target, size_t target_len, const char* source, size_t s LWIP_ASSERT("target_len is too short", target_len >= len); for (i = 0; i < source_len_b64; i++) { - u8_t b = (i < source_len ? source[i] : 0); + u8_t b = (i < source_len ? (u8_t)source[i] : 0); for (j = 7; j >= 0; j--, x--) { - u8_t shift = ((b & (1 << j)) != 0) ? 1 : 0; - current |= shift << x; + if ((b & (1 << j)) != 0) { + current = (u8_t)(current | (1U << x)); + } if (x == 0) { target[target_idx++] = base64_table[current]; x = 6; @@ -987,15 +988,23 @@ again: * the same on every line. */ /* find CRLF */ - crlf = pbuf_memfind(s->p, SMTP_CRLF, SMTP_CRLF_LEN, offset + 4); + if (offset > 0xFFFF - 4) { + /* would overflow */ + return ERR_VAL; + } + crlf = pbuf_memfind(s->p, SMTP_CRLF, SMTP_CRLF_LEN, (u16_t)(offset + 4)); if (crlf == 0xFFFF) { /* no CRLF found */ return ERR_VAL; } - sp = pbuf_get_at(s->p, offset + 3); + sp = pbuf_get_at(s->p, (u16_t)(offset + 3)); if (sp == '-') { /* no space after response code -> try next line */ - offset = crlf + 2; + offset = (u16_t)(crlf + 2); + if (offset < crlf) { + /* overflow */ + return ERR_VAL; + } goto again; } else if (sp == ' ') { /* CRLF found after response code + space -> valid response */ @@ -1015,7 +1024,7 @@ smtp_prepare_helo(struct smtp_session *s, u16_t *tx_buf_len, struct altcp_pcb *p ipa_len = strlen(ipa); LWIP_ASSERT("string too long", ipa_len <= (SMTP_TX_BUF_LEN-SMTP_CMD_EHLO_1_LEN-SMTP_CMD_EHLO_2_LEN)); - *tx_buf_len = SMTP_CMD_EHLO_1_LEN + (u16_t)ipa_len + SMTP_CMD_EHLO_2_LEN; + *tx_buf_len = (u16_t)(SMTP_CMD_EHLO_1_LEN + (u16_t)ipa_len + SMTP_CMD_EHLO_2_LEN); LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN); SMEMCPY(s->tx_buf, SMTP_CMD_EHLO_1, SMTP_CMD_EHLO_1_LEN); @@ -1041,7 +1050,7 @@ smtp_prepare_auth_or_mail(struct smtp_session *s, u16_t *tx_buf_len) u16_t crlf = pbuf_memfind(s->p, SMTP_CRLF, SMTP_CRLF_LEN, auth); if ((crlf != 0xFFFF) && (crlf > auth)) { /* use tx_buf temporarily */ - u16_t copied = pbuf_copy_partial(s->p, s->tx_buf, crlf - auth, auth); + u16_t copied = pbuf_copy_partial(s->p, s->tx_buf, (u16_t)(crlf - auth), auth); if (copied != 0) { char *sep = s->tx_buf + SMTP_KEYWORD_AUTH_LEN; s->tx_buf[copied] = 0; @@ -1057,7 +1066,7 @@ smtp_prepare_auth_or_mail(struct smtp_session *s, u16_t *tx_buf_len) SMTP_TX_BUF_LEN - SMTP_CMD_AUTHPLAIN_1_LEN, SMTP_AUTH_PLAIN_DATA(s), SMTP_AUTH_PLAIN_LEN(s)); LWIP_ASSERT("string too long", auth_len <= (SMTP_TX_BUF_LEN-SMTP_CMD_AUTHPLAIN_1_LEN-SMTP_CMD_AUTHPLAIN_2_LEN)); - *tx_buf_len = SMTP_CMD_AUTHPLAIN_1_LEN + SMTP_CMD_AUTHPLAIN_2_LEN + (u16_t)auth_len; + *tx_buf_len = (u16_t)(SMTP_CMD_AUTHPLAIN_1_LEN + SMTP_CMD_AUTHPLAIN_2_LEN + (u16_t)auth_len); SMEMCPY(&s->tx_buf[SMTP_CMD_AUTHPLAIN_1_LEN + auth_len], SMTP_CMD_AUTHPLAIN_2, SMTP_CMD_AUTHPLAIN_2_LEN); return SMTP_AUTH_PLAIN; @@ -1090,8 +1099,8 @@ smtp_prepare_auth_login_uname(struct smtp_session *s, u16_t *tx_buf_len) SMTP_USERNAME(s), strlen(SMTP_USERNAME(s))); /* @todo: support base64-encoded longer than 64k */ LWIP_ASSERT("string too long", base64_len <= 0xffff); - LWIP_ASSERT("tx_buf overflow detected", base64_len + SMTP_CRLF_LEN <= SMTP_TX_BUF_LEN); - *tx_buf_len = (u16_t)base64_len + SMTP_CRLF_LEN; + LWIP_ASSERT("tx_buf overflow detected", base64_len <= SMTP_TX_BUF_LEN - SMTP_CRLF_LEN); + *tx_buf_len = (u16_t)(base64_len + SMTP_CRLF_LEN); SMEMCPY(&s->tx_buf[base64_len], SMTP_CRLF, SMTP_CRLF_LEN); s->tx_buf[*tx_buf_len] = 0; @@ -1106,8 +1115,8 @@ smtp_prepare_auth_login_pass(struct smtp_session *s, u16_t *tx_buf_len) SMTP_PASS(s), strlen(SMTP_PASS(s))); /* @todo: support base64-encoded longer than 64k */ LWIP_ASSERT("string too long", base64_len <= 0xffff); - LWIP_ASSERT("tx_buf overflow detected", base64_len + SMTP_CRLF_LEN <= SMTP_TX_BUF_LEN); - *tx_buf_len = (u16_t)base64_len + SMTP_CRLF_LEN; + LWIP_ASSERT("tx_buf overflow detected", base64_len <= SMTP_TX_BUF_LEN - SMTP_CRLF_LEN); + *tx_buf_len = (u16_t)(base64_len + SMTP_CRLF_LEN); SMEMCPY(&s->tx_buf[base64_len], SMTP_CRLF, SMTP_CRLF_LEN); s->tx_buf[*tx_buf_len] = 0; @@ -1120,8 +1129,8 @@ static enum smtp_session_state smtp_prepare_mail(struct smtp_session *s, u16_t *tx_buf_len) { char *target = s->tx_buf; - *tx_buf_len = SMTP_CMD_MAIL_1_LEN + SMTP_CMD_MAIL_2_LEN + s->from_len; - LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN); + LWIP_ASSERT("tx_buf overflow detected", s->from_len <= (SMTP_TX_BUF_LEN - SMTP_CMD_MAIL_1_LEN - SMTP_CMD_MAIL_2_LEN)); + *tx_buf_len = (u16_t)(SMTP_CMD_MAIL_1_LEN + SMTP_CMD_MAIL_2_LEN + s->from_len); target[*tx_buf_len] = 0; SMEMCPY(target, SMTP_CMD_MAIL_1, SMTP_CMD_MAIL_1_LEN); @@ -1137,8 +1146,8 @@ static enum smtp_session_state smtp_prepare_rcpt(struct smtp_session *s, u16_t *tx_buf_len) { char *target = s->tx_buf; - *tx_buf_len = SMTP_CMD_RCPT_1_LEN + SMTP_CMD_RCPT_2_LEN + s->to_len; - LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN); + LWIP_ASSERT("tx_buf overflow detected", s->to_len <= (SMTP_TX_BUF_LEN - SMTP_CMD_RCPT_1_LEN - SMTP_CMD_RCPT_2_LEN)); + *tx_buf_len = (u16_t)(SMTP_CMD_RCPT_1_LEN + SMTP_CMD_RCPT_2_LEN + s->to_len); target[*tx_buf_len] = 0; SMEMCPY(target, SMTP_CMD_RCPT_1, SMTP_CMD_RCPT_1_LEN); @@ -1154,10 +1163,11 @@ static enum smtp_session_state smtp_prepare_header(struct smtp_session *s, u16_t *tx_buf_len) { char *target = s->tx_buf; - *tx_buf_len = SMTP_CMD_HEADER_1_LEN + SMTP_CMD_HEADER_2_LEN + + int len = SMTP_CMD_HEADER_1_LEN + SMTP_CMD_HEADER_2_LEN + SMTP_CMD_HEADER_3_LEN + SMTP_CMD_HEADER_4_LEN + s->from_len + s->to_len + s->subject_len; - LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN); + LWIP_ASSERT("tx_buf overflow detected", len > 0 && len <= SMTP_TX_BUF_LEN); + *tx_buf_len = (u16_t)len; target[*tx_buf_len] = 0; SMEMCPY(target, SMTP_CMD_HEADER_1, SMTP_CMD_HEADER_1_LEN); @@ -1201,7 +1211,7 @@ smtp_send_body(struct smtp_session *s, struct altcp_pcb *pcb) } else #endif /* SMTP_BODYDH */ { - u16_t send_len = s->body_len - s->body_sent; + u16_t send_len = (u16_t)(s->body_len - s->body_sent); if (send_len > 0) { u16_t snd_buf = altcp_sndbuf(pcb); if (send_len > snd_buf) { @@ -1212,7 +1222,7 @@ smtp_send_body(struct smtp_session *s, struct altcp_pcb *pcb) err = altcp_write(pcb, &s->body[s->body_sent], (u16_t)send_len, TCP_WRITE_FLAG_COPY); if (err == ERR_OK) { s->timer = SMTP_TIMEOUT_DATABLOCK; - s->body_sent += send_len; + s->body_sent = (u16_t)(s->body_sent + send_len); if (s->body_sent < s->body_len) { LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_send_body: %d of %d bytes written\n", s->body_sent, s->body_len)); diff --git a/src/apps/snmp/snmp_core.c b/src/apps/snmp/snmp_core.c index 871095a6..0fb2d990 100644 --- a/src/apps/snmp/snmp_core.c +++ b/src/apps/snmp/snmp_core.c @@ -193,6 +193,9 @@ #if (!LWIP_UDP && LWIP_SNMP) #error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h" #endif +#if SNMP_MAX_OBJ_ID_LEN > 255 + #error "SNMP_MAX_OBJ_ID_LEN must fit into an u8_t" +#endif struct snmp_statistics snmp_stats; static const struct snmp_obj_id snmp_device_enterprise_oid_default = {SNMP_DEVICE_ENTERPRISE_OID_LEN, SNMP_DEVICE_ENTERPRISE_OID}; @@ -509,10 +512,10 @@ snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip) u8_t snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port) { - u8_t idx = 0; + u8_t idx; /* InetAddressType + InetAddress */ - idx += snmp_oid_to_ip(&oid[idx], oid_len-idx, ip); + idx = snmp_oid_to_ip(&oid[0], oid_len, ip); if (idx == 0) { return 0; } @@ -601,7 +604,7 @@ snmp_oid_append(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) if (oid_len > 0) { MEMCPY(&target->id[target->len], oid, oid_len * sizeof(u32_t)); - target->len += oid_len; + target->len = (u8_t)(target->len + oid_len); } } diff --git a/src/apps/sntp/sntp.c b/src/apps/sntp/sntp.c index edbeff1a..e51cf628 100644 --- a/src/apps/sntp/sntp.c +++ b/src/apps/sntp/sntp.c @@ -110,7 +110,7 @@ #define SNTP_OFFSET_TRANSMIT_TIME 40 /* Number of seconds between 1970 and Feb 7, 2036 06:28:16 UTC (epoch 1) */ -#define DIFF_SEC_1970_2036 ((u32_t)2085978496L) +#define DIFF_SEC_1970_2036 ((s32_t)2085978496L) /** Convert NTP timestamp fraction to microseconds. */ @@ -268,7 +268,7 @@ static const char * sntp_format_time(s32_t sec) { time_t ut; - ut = (u32_t)((u32_t)sec + DIFF_SEC_1970_2036); + ut = (time_t)((time_t)sec + (time_t)DIFF_SEC_1970_2036); return ctime(&ut); } #endif /* LWIP_DEBUG && !sntp_format_time */ @@ -282,7 +282,7 @@ sntp_process(const struct sntp_timestamps *timestamps) s32_t sec; u32_t frac; - sec = lwip_ntohl(timestamps->xmit.sec); + sec = (s32_t)lwip_ntohl(timestamps->xmit.sec); frac = lwip_ntohl(timestamps->xmit.frac); #if SNTP_COMP_ROUNDTRIP @@ -311,7 +311,7 @@ sntp_process(const struct sntp_timestamps *timestamps) /* Clock offset calculation according to RFC 4330 */ t4 += ((t2 - t1) + (t3 - t4)) / 2; - sec = (u32_t)((u64_t)t4 >> 32); + sec = (s32_t)((u64_t)t4 >> 32); frac = (u32_t)((u64_t)t4); } } @@ -334,10 +334,11 @@ sntp_initialize_request(struct sntp_msg *req) #if SNTP_CHECK_RESPONSE >= 2 || SNTP_COMP_ROUNDTRIP { + s32_t secs; u32_t sec, frac; /* Get the transmit timestamp */ - SNTP_GET_SYSTEM_TIME_NTP(sec, frac); - sec = lwip_htonl(sec); + SNTP_GET_SYSTEM_TIME_NTP(secs, frac); + sec = lwip_htonl((u32_t)secs); frac = lwip_htonl(frac); # if SNTP_CHECK_RESPONSE >= 2 diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 9ecb6298..006ec08b 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -62,7 +62,7 @@ #include /** Initial CWND calculation as defined RFC 2581 */ -#define LWIP_TCP_CALC_INITIAL_CWND(mss) LWIP_MIN((4U * (mss)), LWIP_MAX((2U * (mss)), 4380U)); +#define LWIP_TCP_CALC_INITIAL_CWND(mss) ((tcpwnd_size_t)LWIP_MIN((4U * (mss)), LWIP_MAX((2U * (mss)), 4380U))) /* These variables are global to all functions involved in the input processing of TCP segments. They are set by the tcp_input() @@ -190,11 +190,11 @@ tcp_input(struct pbuf *p, struct netif *inp) /* determine how long the first and second parts of the options are */ tcphdr_opt1len = p->len; - opt2len = tcphdr_optlen - tcphdr_opt1len; + opt2len = (u16_t)(tcphdr_optlen - tcphdr_opt1len); /* options continue in the next pbuf: set p to zero length and hide the options in the next pbuf (adjusting p->tot_len) */ - pbuf_header(p, -(s16_t)tcphdr_opt1len); + pbuf_header(p, (s16_t)-(s16_t)tcphdr_opt1len); /* check that the options fit in the second pbuf */ if (opt2len > p->next->len) { @@ -209,8 +209,8 @@ tcp_input(struct pbuf *p, struct netif *inp) /* advance p->next to point after the options, and manually adjust p->tot_len to keep it consistent with the changed p->next */ - pbuf_header(p->next, -(s16_t)opt2len); - p->tot_len -= opt2len; + pbuf_header(p->next, (s16_t)-(s16_t)opt2len); + p->tot_len = (u16_t)(p->tot_len - opt2len); LWIP_ASSERT("p->len == 0", p->len == 0); LWIP_ASSERT("p->tot_len == p->next->tot_len", p->tot_len == p->next->tot_len); @@ -224,7 +224,16 @@ tcp_input(struct pbuf *p, struct netif *inp) tcphdr->wnd = lwip_ntohs(tcphdr->wnd); flags = TCPH_FLAGS(tcphdr); - tcplen = p->tot_len + ((flags & (TCP_FIN | TCP_SYN)) ? 1 : 0); + tcplen = p->tot_len; + if (flags & (TCP_FIN | TCP_SYN)) { + tcplen++; + if (tcplen < p->tot_len) { + /* u16_t overflow, cannot handle this */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: length u16_t overflow, cannot handle this\n")); + TCP_STATS_INC(tcp.lenerr); + goto dropped; + } + } /* Demultiplex an incoming segment. First, we check if it is destined for an active connection. */ @@ -753,7 +762,7 @@ tcp_process(struct tcp_pcb *pcb) LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: Connection RESET\n")); LWIP_ASSERT("tcp_input: pcb->state != CLOSED", pcb->state != CLOSED); recv_flags |= TF_RESET; - pcb->flags &= ~TF_ACK_DELAY; + tcp_clear_flags(pcb, TF_ACK_DELAY); return ERR_RST; } else { LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: unacceptable reset seqno %"U32_F" rcv_nxt %"U32_F"\n", @@ -1038,8 +1047,8 @@ tcp_free_acked_segments(struct tcp_pcb *pcb, struct tcp_seg *seg_list, const cha (tcpwnd_size_t)pcb->snd_queuelen)); LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= clen)); - pcb->snd_queuelen -= clen; - recv_acked += next->len; + pcb->snd_queuelen = (u16_t)(pcb->snd_queuelen - clen); + recv_acked = (tcpwnd_size_t)(recv_acked + next->len); tcp_seg_free(next); LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"TCPWNDSIZE_F" (after freeing %s)\n", @@ -1162,7 +1171,7 @@ tcp_receive(struct tcp_pcb *pcb) /* Inflate the congestion window, but not if it means that the value overflows. */ if ((tcpwnd_size_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) { - pcb->cwnd += pcb->mss; + pcb->cwnd = (tcpwnd_size_t)(pcb->cwnd + pcb->mss); } } else if (pcb->dupacks == 3) { /* Do fast retransmit */ @@ -1185,7 +1194,7 @@ tcp_receive(struct tcp_pcb *pcb) in fast retransmit. Also reset the congestion window to the slow start threshold. */ if (pcb->flags & TF_INFR) { - pcb->flags &= ~TF_INFR; + tcp_clear_flags(pcb, TF_INFR); pcb->cwnd = pcb->ssthresh; pcb->bytes_acked = 0; } @@ -1194,7 +1203,7 @@ tcp_receive(struct tcp_pcb *pcb) pcb->nrtx = 0; /* Reset the retransmission time-out. */ - pcb->rto = (pcb->sa >> 3) + pcb->sv; + pcb->rto = (s16_t)((pcb->sa >> 3) + pcb->sv); /* Record how much data this ACK acks */ acked = (tcpwnd_size_t)(ackno - pcb->lastack); @@ -1218,7 +1227,7 @@ tcp_receive(struct tcp_pcb *pcb) /* RFC 3465, section 2.1 Congestion Avoidance */ TCP_WND_INC(pcb->bytes_acked, acked); if (pcb->bytes_acked >= pcb->cwnd) { - pcb->bytes_acked -= pcb->cwnd; + pcb->bytes_acked = (tcpwnd_size_t)(pcb->bytes_acked - pcb->cwnd); TCP_WND_INC(pcb->cwnd, pcb->mss); } LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %"TCPWNDSIZE_F"\n", pcb->cwnd)); @@ -1265,7 +1274,7 @@ tcp_receive(struct tcp_pcb *pcb) } #endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS*/ - pcb->snd_buf += recv_acked; + pcb->snd_buf = (tcpwnd_size_t)(pcb->snd_buf + recv_acked); /* check if this ACK ends our retransmission of in-flight data */ if (pcb->flags & TF_RTO) { /* RTO is done if @@ -1275,10 +1284,10 @@ tcp_receive(struct tcp_pcb *pcb) if (pcb->unacked == NULL) { if ((pcb->unsent == NULL) || (TCP_SEQ_LEQ(pcb->rto_end, lwip_ntohl(pcb->unsent->tcphdr->seqno)))) { - pcb->flags &= ~TF_RTO; + tcp_clear_flags(pcb, TF_RTO); } } else if (TCP_SEQ_LEQ(pcb->rto_end, lwip_ntohl(pcb->unacked->tcphdr->seqno))) { - pcb->flags &= ~TF_RTO; + tcp_clear_flags(pcb, TF_RTO); } } /* End of ACK for new data processing. */ @@ -1302,14 +1311,14 @@ tcp_receive(struct tcp_pcb *pcb) m, (u16_t)(m * TCP_SLOW_INTERVAL))); /* This is taken directly from VJs original code in his paper */ - m = m - (pcb->sa >> 3); - pcb->sa += m; + m = (s16_t)(m - (pcb->sa >> 3)); + pcb->sa = (s16_t)(pcb->sa + m); if (m < 0) { - m = -m; + m = (s16_t)-m; } - m = m - (pcb->sv >> 2); - pcb->sv += m; - pcb->rto = (pcb->sa >> 3) + pcb->sv; + m = (s16_t)(m - (pcb->sv >> 2)); + pcb->sv = (s16_t)(pcb->sv + m); + pcb->rto = (s16_t)((pcb->sa >> 3) + pcb->sv); LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: RTO %"U16_F" (%"U16_F" milliseconds)\n", pcb->rto, (u16_t)(pcb->rto * TCP_SLOW_INTERVAL))); diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index ef69ab05..533e76eb 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1086,7 +1086,7 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) pcb->flags |= (TF_ACK_DELAY | TF_ACK_NOW); } else { /* remove ACK flags from the PCB, as we sent an empty ACK now */ - pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); + tcp_clear_flags(pcb, TF_ACK_DELAY | TF_ACK_NOW); } return err; @@ -1245,7 +1245,7 @@ tcp_output(struct tcp_pcb *pcb) } pcb->unsent = seg->next; if (pcb->state != SYN_SENT) { - pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); + tcp_clear_flags(pcb, TF_ACK_DELAY | TF_ACK_NOW); } snd_nxt = lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg); if (TCP_SEQ_LT(pcb->snd_nxt, snd_nxt)) { @@ -1292,7 +1292,7 @@ tcp_output(struct tcp_pcb *pcb) #endif /* TCP_OVERSIZE */ output_done: - pcb->flags &= ~TF_NAGLEMEMERR; + tcp_clear_flags(pcb, TF_NAGLEMEMERR); return ERR_OK; } diff --git a/src/include/lwip/apps/httpd_opts.h b/src/include/lwip/apps/httpd_opts.h index 86cb1f1d..9bc1a0fc 100644 --- a/src/include/lwip/apps/httpd_opts.h +++ b/src/include/lwip/apps/httpd_opts.h @@ -275,7 +275,7 @@ The best place to define this is the hooks file (@see LWIP_HOOK_FILENAME) */ #if !defined HTTPD_MAX_WRITE_LEN || defined __DOXYGEN__ #if HTTPD_LIMIT_SENDING_TO_2MSS -#define HTTPD_MAX_WRITE_LEN(pcb) (2 * altcp_mss(pcb)) +#define HTTPD_MAX_WRITE_LEN(pcb) ((u16_t)(2 * altcp_mss(pcb))) #endif #endif diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index b1d382f2..abc05d78 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -443,7 +443,7 @@ struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg); #define tcp_ack(pcb) \ do { \ if((pcb)->flags & TF_ACK_DELAY) { \ - (pcb)->flags &= ~TF_ACK_DELAY; \ + tcp_clear_flags((pcb), TF_ACK_DELAY); \ (pcb)->flags |= TF_ACK_NOW; \ } \ else { \ diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 9f40cbe9..cb6a21c8 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -390,11 +390,11 @@ struct in_pktinfo { #define IOC_INOUT (IOC_IN|IOC_OUT) /* 0x20000000 distinguishes new & old ioctl's */ -#define _IO(x,y) (IOC_VOID|((x)<<8)|(y)) +#define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y))) -#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) +#define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) -#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) +#define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) #endif /* !defined(FIONREAD) || !defined(FIONBIO) */ #ifndef FIONREAD diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index 078b90a3..aa079201 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -146,7 +146,7 @@ typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err); /* Increments a tcpwnd_size_t and holds at max value rather than rollover */ #define TCP_WND_INC(wnd, inc) do { \ if ((tcpwnd_size_t)(wnd + inc) >= wnd) { \ - wnd += inc; \ + wnd = (tcpwnd_size_t)(wnd + inc); \ } else { \ wnd = (tcpwnd_size_t)-1; \ } \ @@ -257,9 +257,9 @@ struct tcp_pcb { /* RTT (round trip time) estimation variables */ u32_t rttest; /* RTT estimate in 500ms ticks */ u32_t rtseq; /* sequence number being timed */ - s16_t sa, sv; /* @todo document this */ + s16_t sa, sv; /* @see "Congestion Avoidance and Control" by Van Jacobson and Karels */ - s16_t rto; /* retransmission time-out */ + s16_t rto; /* retransmission time-out (in ticks of TCP_SLOW_INTERVAL) */ u8_t nrtx; /* number of retransmissions */ /* fast retransmit/recovery */