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 <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2023-02-03 12:21:11 +08:00 committed by Xiang Xiao
parent 8d0094f6c9
commit 24cdcd9a6e
1 changed files with 5 additions and 0 deletions

View File

@ -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)
{