[RFC mptcp-next v2 5/8] selftests: mptcp: connect: fix uninitialized peer warning

Geliang Tang posted 8 patches 1 week, 1 day ago
There is a newer version of this series
[RFC mptcp-next v2 5/8] selftests: mptcp: connect: fix uninitialized peer warning
Posted by Geliang Tang 1 week, 1 day ago
From: Geliang Tang <tanggeliang@kylinos.cn>

Initialize 'peer' addrinfo pointer to NULL in main_loop() to fix the
following compiler warning:

1415:37: warning: 'peer' may be used uninitialized [-Wmaybe-uninitialized]
 1415 |                 if (connect(fd, peer->ai_addr, peer->ai_addrlen))
      |                                 ~~~~^~~~~~~~~
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 badb04b58a64..4d7016475218 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -1376,7 +1376,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) {
@@ -1414,7 +1414,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