From: Willy Tarreau Date: Thu, 30 Nov 2023 16:48:03 +0000 (+0100) Subject: BUILD: server: shut a bogus gcc warning on certain ubuntu X-Git-Tag: v2.9-dev12~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=822d45678f20480e9b6431685932601b77f4157f;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/server.c b/src/server.c index c854fc1b7d..5f79c7db6c 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;