[PATCH mptcp-next 10/11] selftests: mptcp: connect: fix maybe-uninitialize warn

Matthieu Baerts (NGI0) posted 11 patches 1 week, 6 days ago
[PATCH mptcp-next 10/11] selftests: mptcp: connect: fix maybe-uninitialize warn
Posted by Matthieu Baerts (NGI0) 1 week, 6 days ago
This warning can be seen with GCC 15.2:

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

This variable is set in sock_connect_mptcp() in some conditions. If not,
this helper returns an error, and the program stops. So this is a false
positive, but better remove it by initialising peer to NULL.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 tools/testing/selftests/net/mptcp/mptcp_connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index b82df82e0594..27a93a25b142 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -1353,8 +1353,8 @@ void xdisconnect(int fd)
 
 int main_loop(void)
 {
+	struct addrinfo *peer = NULL;
 	int fd = 0, ret, fd_in = 0;
-	struct addrinfo *peer;
 	struct wstate winfo;
 
 	if (cfg_input && cfg_sockopt_types.mptfo) {

-- 
2.51.0

Re: [PATCH mptcp-next 10/11] selftests: mptcp: connect: fix maybe-uninitialize warn
Posted by Geliang Tang 1 week, 4 days ago
Hi Matt,

Thanks for this fix. In my previous commit "selftests: mptcp: connect:
fix uninitialized peer warning" [1], I also fixed this.

[1]
https://patchwork.kernel.org/project/mptcp/patch/43931d38bed6e47b1b68d3bdf0a13916a926d190.1763546473.git.tanggeliang@kylinos.cn/

On Fri, 2025-12-26 at 07:40 +0100, Matthieu Baerts (NGI0) wrote:
> This warning can be seen with GCC 15.2:
> 
>   mptcp_connect.c: In function ‘main_loop’:
>   mptcp_connect.c:1422:37: warning: ‘peer’ may be used uninitialized
> [-Wmaybe-uninitialized]
>    1422 |                 if (connect(fd, peer->ai_addr, peer-
> >ai_addrlen))
>         |                                 ~~~~^~~~~~~~~
>   mptcp_connect.c:1377:26: note: ‘peer’ was declared here
>    1377 |         struct addrinfo *peer;
>         |                          ^~~~
> 
> This variable is set in sock_connect_mptcp() in some conditions. If
> not,
> this helper returns an error, and the program stops. So this is a
> false
> positive, but better remove it by initialising peer to NULL.
> 
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

    Reviewed-by: Geliang Tang <geliang@kernel.org>

-Geliang

> ---
>  tools/testing/selftests/net/mptcp/mptcp_connect.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index b82df82e0594..27a93a25b142 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> @@ -1353,8 +1353,8 @@ void xdisconnect(int fd)
>  
>  int main_loop(void)
>  {
> +	struct addrinfo *peer = NULL;
>  	int fd = 0, ret, fd_in = 0;
> -	struct addrinfo *peer;
>  	struct wstate winfo;
>  
>  	if (cfg_input && cfg_sockopt_types.mptfo) {