diff options
author | Denis Ovsienko <denis@ovsienko.info> | 2023-04-22 22:18:43 +0100 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2023-04-23 17:21:05 +0100 |
commit | 02b98a948dfb661c3e04fca91bd9485525d4198f (patch) | |
tree | ffbab0174b5071c2c7f037408e39d547cb780732 /gencode.c | |
parent | ab3f6a677ba66a9679c6f3412f0320a5776842d0 (diff) |
Address a few compiler warnings on Haiku.
In gencode.c instead of casting pointer types copy the data to squelch 4
previously known warnings from GCC and Clang. (Oddly enough, Haiku is
the only OS that unconditionally puts a 32-bit array into the union
inside struct in6_addr, yet the only OS where these warnings appeared.)
In pcap.c add a temporary workaround for ioctl() to squelch two other
Clang warnings:
pcap.c:1619:6: error: missing field 'size' initializer
[-Werror,-Wmissing-field-initializers]
pcap.c:1638:6: error: missing field 'size' initializer
[-Werror,-Wmissing-field-initializers]
With these changes GCC builds are now warning-free, so in build.sh set
LIBPCAP_TAINTED for Clang only and update the comment to show the
current remaining warnings.
Diffstat (limited to 'gencode.c')
-rw-r--r-- | gencode.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -4102,7 +4102,16 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, { struct block *b0, *b1; u_int offset; - uint32_t *a, *m; + /* + * Code below needs to access four separate 32-bit parts of the 128-bit + * IPv6 address and mask. In some OSes this is as simple as using the + * s6_addr32 pseudo-member of struct in6_addr, which contains a union of + * 8-, 16- and 32-bit arrays. In other OSes this is not the case, as + * far as libpcap sees it. Hence copy the data before use to avoid + * potential unaligned memory access and the associated compiler + * warnings (whether genuine or not). + */ + bpf_u_int32 a[4], m[4]; switch (dir) { @@ -4156,8 +4165,8 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, /*NOTREACHED*/ } /* this order is important */ - a = (uint32_t *)addr; - m = (uint32_t *)mask; + memcpy(a, addr, sizeof(a)); + memcpy(m, mask, sizeof(m)); b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3])); b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2])); gen_and(b0, b1); @@ -7186,7 +7195,7 @@ gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2, struct in6_addr *addr; struct in6_addr mask; struct block *b; - uint32_t *a, *m; + bpf_u_int32 a[4], m[4]; /* Same as in gen_hostop6(). */ /* * Catch errors reported by us and routines below us, and return NULL @@ -7215,8 +7224,8 @@ gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2, (0xff << (8 - masklen % 8)) & 0xff; } - a = (uint32_t *)addr; - m = (uint32_t *)&mask; + memcpy(a, addr, sizeof(a)); + memcpy(m, &mask, sizeof(m)); if ((a[0] & ~m[0]) || (a[1] & ~m[1]) || (a[2] & ~m[2]) || (a[3] & ~m[3])) { bpf_error(cstate, "non-network bits set in \"%s/%d\"", s1, masklen); |