Skip to contentSkip to conversation

selftest: net: fix socklen_t type mismatch in sctp_collision test

PATCH Applied Ankit Khushwaha 3 participants 4 messages Oct 28, 2025 – Oct 30, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftest: net: fix socklen_t type mismatch in sctp_collision test

Socket APIs like recvfrom(), accept(), and getsockname() expect socklen_t* arg, but tests were using int variables. This causes -Wpointer-sign warnings on platforms where socklen_t is unsigned.

Change the variable type from int to socklen_t to resolve the warning and ensure type safety across platforms.

warning fixed:

sctp_collision.c:62:70: warning: passing 'int *' to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
62 | ret = recvfrom(sd, buf, sizeof(buf),

									0, (struct sockaddr *)&daddr, &len);
      |                                                           ^~~~

/usr/include/sys/socket.h:165:27: note: passing argument to parameter '__addr_len' here
165 | socklen_t *__restrict __addr_len);
| ^

---
 tools/testing/selftests/net/netfilter/sctp_collision.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/net/netfilter/sctp_collision.c +2 -1
index 21bb1cfd8a85..91df996367e9 100644
@@ -9,7 +9,8 @@
 int main(int argc, char *argv[])
 {
 	struct sockaddr_in saddr = {}, daddr = {};
-	int sd, ret, len = sizeof(daddr);
+	socklen_t len = sizeof(daddr);
 	struct timeval tv = {25, 0};
 	char buf[] = "hello";
+	int sd, ret;
 
Signature · 1 line
2.51.0
reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Ankit Khushwaha
Quoted 15 lines · Ankit Khushwaha

Socket APIs like recvfrom(), accept(), and getsockname() expect socklen_t* arg, but tests were using int variables. This causes -Wpointer-sign warnings on platforms where socklen_t is unsigned.

Change the variable type from int to socklen_t to resolve the warning and ensure type safety across platforms.

warning fixed:

sctp_collision.c:62:70: warning: passing 'int *' to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
62 | ret = recvfrom(sd, buf, sizeof(buf),

									0, (struct sockaddr *)&daddr, &len);
      |                                                           ^~~~
Quoted 7 lines

/usr/include/sys/socket.h:165:27: note: passing argument to parameter '__addr_len' here
165 | socklen_t *__restrict __addr_len);
| ^

Thanks for the update.

#3 lore raw
In reply to Ankit Khushwaha
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 28 Oct 2025 22:59:47 +0530 you wrote:

Socket APIs like recvfrom(), accept(), and getsockname() expect socklen_t* arg, but tests were using int variables. This causes -Wpointer-sign warnings on platforms where socklen_t is unsigned.

Change the variable type from int to socklen_t to resolve the warning and ensure type safety across platforms.

[...]

Here is the summary with links:
- [v2] selftest: net: fix socklen_t type mismatch in sctp_collision test

    https://git.kernel.org/netdev/net-next/c/afb8f6567a5b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html