diff mbox series

[liburing] examples/io_uring-udp: Use a proper cast for `(struct sockaddr *)` argument

Message ID 20220726164310.266060-1-ammar.faizi@intel.com (mailing list archive)
State New
Headers show
Series [liburing] examples/io_uring-udp: Use a proper cast for `(struct sockaddr *)` argument | expand

Commit Message

Ammar Faizi July 26, 2022, 4:44 p.m. UTC
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>

Sometimes the compiler accepts `(struct sockaddr_in *)` and
`(struct sockaddr_in6 *)` 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 errors:

    io_uring-udp.c:134:18: error: incompatible pointer types passing \
    'struct sockaddr_in6 *' to parameter of type 'const struct sockaddr *' \
    [-Werror,-Wincompatible-pointer-types

    io_uring-udp.c:142:18: error: incompatible pointer types passing \
    'struct sockaddr_in *' to parameter of type 'const struct sockaddr *' \
    [-Werror,-Wincompatible-pointer-types]

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

Cc: Dylan Yudaken <dylany@fb.com>
Cc: Facebook Kernel Team <kernel-team@fb.com>
Fixes: 61d472b51e761e61cbf46caea40aaf40d8ed1484 ("add an example for a UDP server")
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 examples/io_uring-udp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


base-commit: 61d472b51e761e61cbf46caea40aaf40d8ed1484

Comments

Jens Axboe July 26, 2022, 4:47 p.m. UTC | #1
On Tue, 26 Jul 2022 23:44:59 +0700, Ammar Faizi wrote:
> From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
> 
> Sometimes the compiler accepts `(struct sockaddr_in *)` and
> `(struct sockaddr_in6 *)` 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 errors:
> 
> [...]

Applied, thanks!

[1/1] examples/io_uring-udp: Use a proper cast for `(struct sockaddr *)` argument
      commit: 1842b2a74f4e914cb094019d0f339baeffa3023b

Best regards,
diff mbox series

Patch

diff --git a/examples/io_uring-udp.c b/examples/io_uring-udp.c
index 77472df..b4ef0a3 100644
--- a/examples/io_uring-udp.c
+++ b/examples/io_uring-udp.c
@@ -131,7 +131,7 @@  static int setup_sock(int af, int port)
 			.sin6_addr = IN6ADDR_ANY_INIT
 		};
 
-		ret = bind(fd, &addr6, sizeof(addr6));
+		ret = bind(fd, (struct sockaddr *) &addr6, sizeof(addr6));
 	} else {
 		struct sockaddr_in addr = {
 			.sin_family = af,
@@ -139,7 +139,7 @@  static int setup_sock(int af, int port)
 			.sin_addr = { INADDR_ANY }
 		};
 
-		ret = bind(fd, &addr, sizeof(addr));
+		ret = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
 	}
 
 	if (ret) {