1
0
Fork 0
mirror of https://passt.top/passt synced 2025-06-13 19:15:34 +02:00

util: Consolidate and improve workarounds for clang-tidy issue 58992

We have several workarounds for a clang-tidy bug where the checker doesn't
recognize that a number of system calls write to - and therefore initialise
- a socket address.  We can't neatly use a suppression, because the bogus
warning shows up some time after the actual system call, when we access
a field of the socket address which clang-tidy erroneously thinks is
uninitialised.

Consolidate these workarounds into one place by using macros to implement
wrappers around affected system calls which add a memset() of the sockaddr
to silence clang-tidy.  This removes the need for the individual memset()
workarounds at the callers - and the somewhat longwinded explanatory
comments.

We can then use a #define to not include the hack in "real" builds, but
only consider it for clang-tidy.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2023-09-21 14:49:39 +10:00 committed by Stefano Brivio
parent 5b6c68c2e4
commit c1d2a070f2
4 changed files with 43 additions and 13 deletions

8
tcp.c
View file

@ -2752,19 +2752,13 @@ void tcp_listen_handler(struct ctx *c, union epoll_ref ref,
const struct timespec *now)
{
struct sockaddr_storage sa;
socklen_t sl = sizeof(sa);
union tcp_conn *conn;
socklen_t sl;
int s;
if (c->no_tcp || c->tcp.conn_count >= TCP_MAX_CONNS)
return;
sl = sizeof(sa);
/* FIXME: Workaround clang-tidy not realizing that accept4()
* writes the socket address. See
* https://github.com/llvm/llvm-project/issues/58992
*/
memset(&sa, 0, sizeof(struct sockaddr_in6));
s = accept4(ref.fd, (struct sockaddr *)&sa, &sl, SOCK_NONBLOCK);
if (s < 0)
return;