[RFC mptcp-next 09/10] selftests: mptcp: connect: fix uninitialized variable warning

Geliang Tang posted 10 patches 1 week, 2 days ago
There is a newer version of this series
[RFC mptcp-next 09/10] selftests: mptcp: connect: fix uninitialized variable warning
Posted by Geliang Tang 1 week, 2 days ago
From: Geliang Tang <tanggeliang@kylinos.cn>

Initialize 'peer' addrinfo pointer to NULL in main_loop() to resolve
compiler warning about potential use of uninitialized variable when
handling repeated connection attempts.

  CC       mptcp_connect
mptcp_connect.c: In function 'main_loop':
mptcp_connect.c:1415:37: warning: 'peer' may be used uninitialized [-Wmaybe-uninitialized]
 1415 |                 if (connect(fd, peer->ai_addr, peer->ai_addrlen))
      |                                 ~~~~^~~~~~~~~
mptcp_connect.c:1368:26: note: 'peer' was declared here
 1368 |         struct addrinfo *peer;
      |                          ^~~~

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_connect.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index e43874610297..bd46639edc92 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -1365,7 +1365,7 @@ void xdisconnect(int fd)
 int main_loop(void)
 {
 	int fd = 0, ret, fd_in = 0;
-	struct addrinfo *peer;
+	struct addrinfo *peer = NULL;
 	struct wstate winfo;
 
 	if (cfg_input && cfg_sockopt_types.mptfo) {
@@ -1405,7 +1405,7 @@ int main_loop(void)
 
 	if (cfg_truncate > 0) {
 		shutdown(fd, SHUT_WR);
-	} else if (--cfg_repeat > 0) {
+	} else if (--cfg_repeat > 0 && peer) {
 		xdisconnect(fd);
 
 		/* the socket could be unblocking at this point, we need the
-- 
2.51.0