From 1d954c3fea050cdd2b929f4dc59822126b94d580 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 4 Feb 2024 11:27:41 +0100 Subject: [PATCH] hurd: Avoid warnings The warning for line 37 was: (With clang version 11.0.1) ------------------------------------------------------------------------ ./pcap-hurd.c:196:35: warning: expression does not compute the number of elements in this array; element type is 'struct bpf_insn', not 'short' [-Wsizeof-array-div] (filter_array_t_filter, FILTER_COUNT); ^~~~~~~~~~~~ ./pcap-hurd.c:37:38: note: expanded from macro 'FILTER_COUNT' #define FILTER_COUNT (sizeof(filter) / sizeof(short)) ~~~~~~ ^ ./pcap-hurd.c:32:24: note: array 'filter' declared here static struct bpf_insn filter[] = { ^ ./pcap-hurd.c:196:35: note: place parentheses around the 'sizeof(short)' expression to silence this warning (filter_array_t)filter, FILTER_COUNT); ^ ./pcap-hurd.c:37:38: note: expanded from macro 'FILTER_COUNT' #define FILTER_COUNT (sizeof(filter) / sizeof(short)) ^ ------------------------------------------------------------------------ But device_set_filter really does want the size in units of shorts. --- pcap-hurd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pcap-hurd.c b/pcap-hurd.c index 408a19123a..3d888b374a 100644 --- a/pcap-hurd.c +++ b/pcap-hurd.c @@ -34,10 +34,13 @@ static struct bpf_insn filter[] = { { BPF_RET | BPF_K, 0, 0, MAXIMUM_SNAPLEN }, }; -#define FILTER_COUNT (sizeof(filter) / sizeof(short)) +/* device_set_filter calls net_set_filter which uses CSPF_BYTES which counts in + * shorts, not elements, so using extra parenthesis to silence compilers which + * believe we are computing wrong here. */ +#define FILTER_COUNT (sizeof(filter) / (sizeof(short))) static int -pcap_read_hurd(pcap_t *p, int cnt, pcap_handler callback, u_char *user) +pcap_read_hurd(pcap_t *p, int cnt _U_, pcap_handler callback, u_char *user) { struct net_rcv_msg *msg; struct pcap_hurd *ph; @@ -258,7 +261,7 @@ pcapint_create_interface(const char *device _U_, char *ebuf) } int -pcapint_platform_finddevs(pcap_if_list_t *alldevsp, char *errbuf) +pcapint_platform_finddevs(pcap_if_list_t *alldevsp _U_, char *errbuf _U_) { return 0; }