From 6101f678f321d8f983efefc39961773a8efff4c5 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sat, 23 Nov 2024 03:25:52 +0200 Subject: [PATCH 1/4] Fix function without prototype I'm not sure why this is considered a function without prototype, but in C function without arguments accept any number of arguments. In this case we want a function that does not accept arguments so we need to use (void). cli.c:64:26: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] 64 | static void print_version() { puts(VERSION); } | ^ | void Signed-off-by: Nir Soffer --- cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.c b/cli.c index d9656f6..5058577 100644 --- a/cli.c +++ b/cli.c @@ -61,7 +61,7 @@ static void print_usage(const char *argv0) { printf("version: " VERSION "\n"); } -static void print_version() { puts(VERSION); } +static void print_version(void) { puts(VERSION); } enum { CLI_OPT_SOCKET_GROUP = CHAR_MAX + 1, From d83ccf018477372db4841a67ceb6938e495f05d4 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sat, 23 Nov 2024 03:32:31 +0200 Subject: [PATCH 2/4] Fix arithmetic on a pointer to void This is a gnu extension reported as warning when using -Wall -Wextra -pedantic. Avoiding it is easy and more clear. main.c:167:51: warning: arithmetic on a pointer to void is a GNU extension [-Wgnu-pointer-arith] 167 | memcpy(src_mac, pdv[i].vm_pkt_iov[0].iov_base + 6, sizeof(src_mac)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ Signed-off-by: Nir Soffer --- main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 3dbf6c1..b16c824 100644 --- a/main.c +++ b/main.c @@ -163,8 +163,9 @@ static void _on_vmnet_packets_available(interface_ref iface, int64_t buf_count, for (int i = 0; i < received_count; i++) { uint8_t dest_mac[6], src_mac[6]; assert(pdv[i].vm_pkt_iov[0].iov_len > 12); - memcpy(dest_mac, pdv[i].vm_pkt_iov[0].iov_base, sizeof(dest_mac)); - memcpy(src_mac, pdv[i].vm_pkt_iov[0].iov_base + 6, sizeof(src_mac)); + const char *packet = (const char *)pdv[i].vm_pkt_iov[0].iov_base; + memcpy(dest_mac, packet, sizeof(dest_mac)); + memcpy(src_mac, packet + 6, sizeof(src_mac)); DEBUGF("[Handler i=%d] Dest %02X:%02X:%02X:%02X:%02X:%02X, Src " "%02X:%02X:%02X:%02X:%02X:%02X,", i, dest_mac[0], dest_mac[1], dest_mac[2], dest_mac[3], dest_mac[4], From 6c43bc727c0d7401a3682dd465a81761863db120 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Sat, 23 Nov 2024 03:39:30 +0200 Subject: [PATCH 3/4] Fix wrong comparison We compare the listen() function pointer to 0 instead of the listen_fd. This "works" because it is an extension. Using -Wall -Wextra -pedantic reveals the error: main.c:456:14: warning: ordered comparison between pointer and zero ('int (*)(int, int)' and 'int') is an extension [-Wpedantic] 456 | if (listen >= 0) { | ~~~~~~ ^ ~ Fix to compare listen_fd, and use -1 since this is is the sentinel value meaning we failed to create the socket. Signed-off-by: Nir Soffer --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index b16c824..5ccdc7a 100644 --- a/main.c +++ b/main.c @@ -453,7 +453,7 @@ int main(int argc, char *argv[]) { if (iface != NULL) { stop(&state, iface); } - if (listen >= 0) { + if (listen_fd != -1) { close(listen_fd); } if (pid_fd != -1) { From 3adaad8ff235b2cdb5dbfe50868b8756a70b0a33 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Wed, 20 Nov 2024 03:18:15 +0200 Subject: [PATCH 4/4] Enable all warnings and pedantic mode This can be an issue for portable code, but we build for single platform and single compiler, so we should be ok. Don't treat warnings as errors to reduced the chance that the build will fail on older macOS versions or future versions. Signed-off-by: Nir Soffer --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1093ed3..359cb95 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ GZIP ?= gzip -9 -n DIFFOSCOPE ?= diffoscope STRIP ?= strip -CFLAGS ?= -O3 +CFLAGS ?= -O3 -Wall -Wextra -pedantic ifeq ($(DEBUG),1) CFLAGS += -g endif