From 748ef4cd6e7d7307b4c91cbe59ad040ef535dbdc Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 5 Sep 2024 21:22:04 +1000 Subject: cppcheck: Work around some cppcheck 2.15.0 redundantInitialization warnings cppcheck-2.15.0 has apparently broadened when it throws a warning about redundant initialization to include some cases where we have an initializer for some fields, but then set other fields in the function body. This is arguably a false positive: although we are technically overwriting the zero-initialization the compiler supplies for fields not explicitly initialized, this sort of construct makes sense when there are some fields we know at the top of the function where the initializer is, but others that require more complex calculation. That said, in the two places this shows up, it's pretty easy to work around. The results are arguably slightly clearer than what we had, since they move the parts of the initialization closer together. So do that rather than having ugly suppressions or dealing with the tedious process of reporting a cppcheck false positive. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- udp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'udp.c') diff --git a/udp.c b/udp.c index ae91027..2ba00c9 100644 --- a/udp.c +++ b/udp.c @@ -773,16 +773,14 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, const void *addr, const char *ifname, in_port_t port) { - union udp_listen_epoll_ref uref = { .port = port }; + union udp_listen_epoll_ref uref = { + .pif = ns ? PIF_SPLICE : PIF_HOST, + .port = port, + }; int r4 = FD_REF_MAX + 1, r6 = FD_REF_MAX + 1; ASSERT(!c->no_udp); - if (ns) - uref.pif = PIF_SPLICE; - else - uref.pif = PIF_HOST; - if (af == AF_UNSPEC && c->ifi4 && c->ifi6) { int s; -- cgit v1.2.3