Skip to content

Commit

Permalink
sim: fix kasan report memalign crash when alignment is 1
Browse files Browse the repository at this point in the history
(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>
  • Loading branch information
GUIDINGLI authored and xiaoxiang781216 committed Feb 8, 2023
1 parent 8d0094f commit 24cdcd9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arch/sim/src/sim/posix/sim_hostmemory.c
Expand Up @@ -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)
{
Expand Down

0 comments on commit 24cdcd9

Please sign in to comment.