On 3/5/26 8:15 AM, Peter Maydell wrote:
In commit eb3f69cac62670 we removed the dependency of this mem plugin on the QEMU headers, but in doing that we introduced undefined behaviour when the plugin accesses unaligned memory. This shows up if you build with the gcc or clang undefined behaviour sanitizer (--enable-ubsan) and run 'make check-tcg', in numerous warnings like:../../tests/tcg/plugins/mem.c:167:27: runtime error: load of misaligned address 0x7f1f300354b1 for type 'uint16_t' (aka 'unsigned short'), which requires 2 byte alignment 0x7f1f300354b1: note: pointer points here 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c ^ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../tests/tcg/plugins/mem.c:167:27 Fix this by rearranging the data reads and writes to use memcpy() instead. Fixes: eb3f69cac62670 ("tests/tcg/plugins/mem.c: remove dependency on qemu headers") Tested-by: Alex Bennée <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Signed-off-by: Peter Maydell <[email protected]> --- tests/tcg/plugins/mem.c | 71 +++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 41 deletions(-)
Reviewed-by: Pierrick Bouvier <[email protected]>
