From d0e84b99de6b4cc227350c1431650b22afdfd0d8 Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Thu, 25 Dec 2025 12:43:42 +0100 Subject: [PATCH] Fix unaligned memory access with memcpy --- mypyc/lib-rt/librt_internal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mypyc/lib-rt/librt_internal.c b/mypyc/lib-rt/librt_internal.c index 9c57d8bef72c..ddb7e10d4b03 100644 --- a/mypyc/lib-rt/librt_internal.c +++ b/mypyc/lib-rt/librt_internal.c @@ -3,6 +3,7 @@ #define PY_SSIZE_T_CLEAN #include #include +#include #include "CPy.h" #define LIBRT_INTERNAL_MODULE #include "librt_internal.h" @@ -39,13 +40,14 @@ #define _READ(result, data, type) \ do { \ - *(result) = *(type *)(((ReadBufferObject *)data)->ptr); \ + memcpy((void *) result, ((ReadBufferObject *)data)->ptr, sizeof(type)); \ ((ReadBufferObject *)data)->ptr += sizeof(type); \ } while (0) #define _WRITE(data, type, v) \ do { \ - *(type *)(((WriteBufferObject *)data)->ptr) = v; \ + type temp = v; \ + memcpy(((WriteBufferObject *)data)->ptr, (const void *) &temp, sizeof(type)); \ ((WriteBufferObject *)data)->ptr += sizeof(type); \ } while (0)