On 29/5/24 15:31, Thomas Huth wrote:
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 <th...@redhat.com>
---
  io/channel-socket.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>


Reply via email to