]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: server: shut a bogus gcc warning on certain ubuntu
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Nov 2023 16:48:03 +0000 (17:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Nov 2023 16:48:03 +0000 (17:48 +0100)
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

index c854fc1b7d526b5cddd61da3f16e82b19adba5e6..5f79c7db6c170bb2beddd696272e401b8c657701 100644 (file)
@@ -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;