From 822d45678f20480e9b6431685932601b77f4157f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 30 Nov 2023 17:48:03 +0100 Subject: [PATCH] BUILD: server: shut a bogus gcc warning on certain ubuntu On ubuntu 20.04 and 22.04 with gcc 9.4 and 11.4 respectively, we get the following warning: src/server.c: In function 'srv_update_addr_port': src/server.c:4027:3: warning: 'new_port' may be used uninitialized in this function [-Wmaybe-uninitialized] 4027 | _srv_event_hdl_prepare_inetaddr(&cb_data.addr, &s->addr, s->svc_port, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4028 | ((ip_change) ? &sa : &s->addr), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4029 | ((port_change) ? new_port : s->svc_port), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4030 | 1); | ~~ It's clearly wrong, port_change only changes from 0 to anything else *after* assigning new_port. Let's just preset new_port to zero instead of trying to play smart with the compiler. --- src/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index c854fc1..5f79c7d 100644 --- a/src/server.c +++ b/src/server.c @@ -3902,7 +3902,7 @@ const char *srv_update_addr_port(struct server *s, const char *addr, const char struct sockaddr_storage sa; int ret; char current_addr[INET6_ADDRSTRLEN]; - uint16_t current_port, new_port; + uint16_t current_port, new_port = 0; struct buffer *msg; int ip_change = 0; int port_change = 0; -- 1.7.10.4