From 24cdcd9a6e6745a06c29da148939551f6f983124 Mon Sep 17 00:00:00 2001 From: ligd Date: Fri, 3 Feb 2023 12:21:11 +0800 Subject: [PATCH] sim: fix kasan report memalign crash when alignment is 1 (0)Allocating 3 bytes aligned to 0x00000001 ================================================================= ==1461685==ERROR: AddressSanitizer: invalid alignment requested in posix_memalign: 1, alignment must be a power of two and a multiple of sizeof(void*) == 4 (thread T0) #0 0xf7ab1c2f in __interceptor_posix_memalign ../../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:226 Signed-off-by: ligd --- arch/sim/src/sim/posix/sim_hostmemory.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/sim/src/sim/posix/sim_hostmemory.c b/arch/sim/src/sim/posix/sim_hostmemory.c index b7f2a226ac..0b0f308e1a 100644 --- a/arch/sim/src/sim/posix/sim_hostmemory.c +++ b/arch/sim/src/sim/posix/sim_hostmemory.c @@ -156,6 +156,11 @@ void *host_memalign(size_t alignment, size_t size) void *p; int error; + if (alignment < sizeof(void *)) + { + alignment = sizeof(void *); + } + error = posix_memalign(&p, alignment, size); if (error != 0) {