Skip to contentSkip to conversation

test/helpers: Use a proper cast for `(struct sockaddr *)` argument

PATCH Applied Ammar Faizi 2 participants 2 messages Jul 3, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/helpers: Use a proper cast for `(struct sockaddr *)` argument

From: Ammar Faizi <[email protected]>

Sometimes the compiler accepts (struct sockaddr_in *) to be passed in to (struct sockaddr *) without a cast. But not all compilers agree with that. Building with clang 13.0.1 yields the following error:

error: incompatible pointer types passing 'struct sockaddr_in *' to \
parameter of type 'struct sockaddr *' [-Werror,-Wincompatible-pointer-types]

Explicitly cast the pointer to (struct sockaddr *) to avoid this error.

Cc Dylan Yudaken <[email protected]>
Fixes 9167905ca187064ba1d9ac4c8bb8484157bef86b ("add t_create_socket_pair")
---
 test/helpers.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
test/helpers.c +6 -4
index 3660cc0..0146533 100644
@@ -190,26 +190,28 @@ int t_create_socket_pair(int fd[2], bool stream)
 		goto errno_cleanup;
 	}
 
-	if (getsockname(fd[0], &serv_addr, (socklen_t *)&paddrlen)) {
+	if (getsockname(fd[0], (struct sockaddr *)&serv_addr,
+			(socklen_t *)&paddrlen)) {
 		fprintf(stderr, "getsockname failed\n");
 		goto errno_cleanup;
 	}
 	inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
 
-	if (connect(fd[1], &serv_addr, paddrlen)) {
+	if (connect(fd[1], (struct sockaddr *)&serv_addr, paddrlen)) {
 		fprintf(stderr, "connect failed\n");
 		goto errno_cleanup;
 	}
 
 	if (!stream) {
 		/* connect the other udp side */
-		if (getsockname(fd[1], &serv_addr, (socklen_t *)&paddrlen)) {
+		if (getsockname(fd[1], (struct sockaddr *)&serv_addr,
+				(socklen_t *)&paddrlen)) {
 			fprintf(stderr, "getsockname failed\n");
 			goto errno_cleanup;
 		}
 		inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
 
-		if (connect(fd[0], &serv_addr, paddrlen)) {
+		if (connect(fd[0], (struct sockaddr *)&serv_addr, paddrlen)) {
 			fprintf(stderr, "connect failed\n");
 			goto errno_cleanup;
 		}

base-commit: 98c14a04e2c0dcdfbb71372a1a209ed889fb3e4d

Signature · 1 line
Ammar Faizi
maintainer Applied
#1 lore raw
Quoted 10 lines · Ammar Faizi

From: Ammar Faizi <[email protected]>

Sometimes the compiler accepts (struct sockaddr_in *) to be passed in to (struct sockaddr *) without a cast. But not all compilers agree with that. Building with clang 13.0.1 yields the following error:

error: incompatible pointer types passing 'struct sockaddr_in *' to \
parameter of type 'struct sockaddr *' [-Werror,-Wincompatible-pointer-types]

[...]

Applied, thanks!

[1/1] test/helpers: Use a proper cast for (struct sockaddr *) argument

      commit: 752c325dcde43be8d87f83b16d346beac5e1de2a

Best regards,

Signature · 1 line
Jens Axboe