From 2ea10a4c234e3df19d35a13a80a8b111a2297c33 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Aug 2020 21:37:31 +0200 Subject: [PATCH] n-dhcp4/connection: avoid compiler warning in n_dhcp4_c_connection_connect() about fd_udp uninitialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With LTO and optimizations enabled, we get a compiler warning about fd_udp not initialized: ../src/n-dhcp4-c-connection.c: In function ‘n_dhcp4_c_connection_connect’: ../src/n-dhcp4-c-connection.c:196:13: error: ‘fd_udp’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 196 | r = epoll_ctl(connection->fd_epoll, | ^ ../src/n-dhcp4-c-connection.c:185:16: note: ‘fd_udp’ was declared here 185 | int r, fd_udp; | ^ https://github.com/nettools/n-dhcp4/commit/6c6e9368989eae699448611fc82f41d50bd39dd9 (cherry picked from commit 4e0e002092c763e989613018b1eb1ed9972849be) --- shared/n-dhcp4/src/n-dhcp4-c-connection.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/shared/n-dhcp4/src/n-dhcp4-c-connection.c b/shared/n-dhcp4/src/n-dhcp4-c-connection.c index 8c32a984dd..701df1f60b 100644 --- a/shared/n-dhcp4/src/n-dhcp4-c-connection.c +++ b/shared/n-dhcp4/src/n-dhcp4-c-connection.c @@ -182,7 +182,8 @@ int n_dhcp4_c_connection_listen(NDhcp4CConnection *connection) { int n_dhcp4_c_connection_connect(NDhcp4CConnection *connection, const struct in_addr *client, const struct in_addr *server) { - int r, fd_udp; + _c_cleanup_(c_closep) int fd_udp = -1; + int r; c_assert(connection->state == N_DHCP4_C_CONNECTION_STATE_PACKET); @@ -200,27 +201,21 @@ int n_dhcp4_c_connection_connect(NDhcp4CConnection *connection, .events = EPOLLIN, .data = { .u32 = N_DHCP4_CLIENT_EPOLL_IO }, }); - if (r < 0) { - r = -errno; - goto exit_fd; - } + if (r < 0) + return -errno; r = packet_shutdown(connection->fd_packet); - if (r < 0) - goto exit_epoll; + if (r < 0) { + epoll_ctl(connection->fd_epoll, EPOLL_CTL_DEL, fd_udp, NULL); + return r; + } connection->state = N_DHCP4_C_CONNECTION_STATE_DRAINING; connection->fd_udp = fd_udp; + fd_udp = -1; connection->client_ip = client->s_addr; connection->server_ip = server->s_addr; - fd_udp = -1; return 0; - -exit_epoll: - epoll_ctl(connection->fd_epoll, EPOLL_CTL_DEL, fd_udp, NULL); -exit_fd: - close(fd_udp); - return r; } void n_dhcp4_c_connection_close(NDhcp4CConnection *connection) {