qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io/channel-socket: Fix -fsanitize=undefined problem with latest Clang
@ 2024-05-29 13:31 Thomas Huth
  2024-05-29 13:52 ` Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Thomas Huth @ 2024-05-29 13:31 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel; +Cc: qemu-trivial, Akihiko Odaki

Casting function pointers from one type to another causes undefined
behavior errors when compiling with -fsanitize=undefined with Clang v18:

 $ QTEST_QEMU_BINARY=./qemu-system-mips64 tests/qtest/netdev-socket
 TAP version 13
 # random seed: R02S4424f4f460de783fdd3d72c5571d3adc
 1..10
 # Start of mips64 tests
 # Start of netdev tests
 # Start of stream tests
 # starting QEMU: exec ./qemu-system-mips64 -qtest unix:/tmp/qtest-1213196.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-1213196.qmp,id=char0 -mon chardev=char0,mode=control -display none -audio none -nodefaults -M none -netdev stream,id=st0,addr.type=fd,addr.str=3 -accel qtest
 ../io/task.c:78:13: runtime error: call to function qapi_free_SocketAddress through pointer to incorrect function type 'void (*)(void *)'
 /tmp/qemu-sanitize/qapi/qapi-types-sockets.c:170: note: qapi_free_SocketAddress defined here
 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../io/task.c:78:13

Add a wrapper function to avoid the problem.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 io/channel-socket.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/io/channel-socket.c b/io/channel-socket.c
index 3a899b0608..aa2a1c8586 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -193,6 +193,10 @@ static void qio_channel_socket_connect_worker(QIOTask *task,
     qio_task_set_error(task, err);
 }
 
+static void qio_qapi_free_SocketAddress(gpointer sa)
+{
+    qapi_free_SocketAddress(sa);
+}
 
 void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
                                       SocketAddress *addr,
@@ -213,7 +217,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
     qio_task_run_in_thread(task,
                            qio_channel_socket_connect_worker,
                            addrCopy,
-                           (GDestroyNotify)qapi_free_SocketAddress,
+                           qio_qapi_free_SocketAddress,
                            context);
 }
 
-- 
2.45.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-06-03 17:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-29 13:31 [PATCH] io/channel-socket: Fix -fsanitize=undefined problem with latest Clang Thomas Huth
2024-05-29 13:52 ` Philippe Mathieu-Daudé
2024-05-29 13:53 ` Peter Maydell
2024-06-03 12:48   ` Daniel P. Berrangé
2024-06-03 14:38     ` Thomas Huth
2024-06-03 14:49       ` Daniel P. Berrangé
2024-06-03 14:58         ` Peter Maydell
2024-06-03 15:12           ` Peter Maydell
2024-06-03 15:52             ` Daniel P. Berrangé
2024-06-03 15:55               ` Thomas Huth
2024-06-03 14:47 ` Alex Bennée
2024-06-03 14:50   ` Daniel P. Berrangé
2024-06-03 17:46     ` Alex Bennée
2024-06-03 17:55       ` Daniel P. Berrangé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).