From c46d125569a215226602a7d4b9c346ee074fe365 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 6 May 2021 19:25:09 +0200 Subject: Check the alignment in posix_memalign() earlier Make sure all conditions to do a proper memory allocation are satisfied before a zero size memory allocation is performed. Update #4390. --- cpukit/libcsupport/src/posix_memalign.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cpukit/libcsupport') diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c index 4e89413c24..418de99275 100644 --- a/cpukit/libcsupport/src/posix_memalign.c +++ b/cpukit/libcsupport/src/posix_memalign.c @@ -37,10 +37,6 @@ int posix_memalign( *memptr = NULL; - if ( size == 0 ) { - return 0; - } - if ( alignment < sizeof( void * ) ) { return EINVAL; } @@ -49,6 +45,10 @@ int posix_memalign( return EINVAL; } + if ( size == 0 ) { + return 0; + } + *memptr = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 ); if ( *memptr == NULL ) { -- cgit v1.2.3