From d0c4523ccd8998a70262fb11e015ea807d4aaba7 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 1 May 2018 14:59:06 +0200 Subject: [PATCH] Fix all compiler warnings found using -Wall -W -pedantic. --- Makefile | 2 +- selftest.c | 4 ++-- utcp.c | 23 ++++++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 9748954..faa2f66 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS ?= -Og -Wall -g +CFLAGS ?= -Og -Wall -W -pedantic -g CFLAGS += -std=c99 -DUTCP_DEBUG BIN = selftest test diff --git a/selftest.c b/selftest.c index 0b8a891..dacdd0c 100644 --- a/selftest.c +++ b/selftest.c @@ -13,9 +13,9 @@ struct utcp_connection *c; ssize_t do_recv(struct utcp_connection *x, const void *data, size_t len) { if(!len) { if(errno) { - fprintf(stderr, "%p Error: %s\n", x->utcp, strerror(errno)); + fprintf(stderr, "%p Error: %s\n", (void *)x->utcp, strerror(errno)); } else { - fprintf(stderr, "%p Connection closed by peer\n", x->utcp); + fprintf(stderr, "%p Connection closed by peer\n", (void *)x->utcp); } if(x != c) { diff --git a/utcp.c b/utcp.c index b939dc8..49b89ab 100644 --- a/utcp.c +++ b/utcp.c @@ -892,6 +892,8 @@ static void handle_incoming_data(struct utcp_connection *c, uint32_t seq, const ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { + const uint8_t *ptr = data; + if(!utcp) { errno = EFAULT; return -1; @@ -919,8 +921,8 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { // Make a copy from the potentially unaligned data to a struct hdr - memcpy(&hdr, data, sizeof(hdr)); - data += sizeof(hdr); + memcpy(&hdr, ptr, sizeof(hdr)); + ptr += sizeof(hdr); len -= sizeof(hdr); // Drop packets with an unknown CTL flag @@ -952,7 +954,7 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { return -1; } - init = data; + init = ptr; break; default: @@ -961,7 +963,7 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { } len -= auxlen; - data += auxlen; + ptr += auxlen; if(!(aux & 0x800)) { break; @@ -972,9 +974,9 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { return -1; } - memcpy(&aux, data, 2); + memcpy(&aux, ptr, 2); len -= 2; - data += 2; + ptr += 2; } // Try to match the packet to an existing connection @@ -1112,7 +1114,7 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { acceptable = len > (size_t) - rcv_offset; if(acceptable) { - data -= rcv_offset; + ptr -= rcv_offset; len += rcv_offset; hdr.seq -= rcv_offset; } @@ -1222,13 +1224,16 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { } } + uint32_t advanced; + if(!(hdr.ctl & ACK)) { + advanced = 0; goto skip_ack; } // 3. Advance snd.una - uint32_t advanced = seqdiff(hdr.ack, c->snd.una); + advanced = seqdiff(hdr.ack, c->snd.una); prevrcvnxt = c->rcv.nxt; if(advanced) { @@ -1420,7 +1425,7 @@ skip_ack: return 0; } - handle_incoming_data(c, hdr.seq, data, len); + handle_incoming_data(c, hdr.seq, ptr, len); } // 7. Process FIN stuff -- 2.39.5