forked from Imagelibrary/rtems
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.
This commit is contained in:
@@ -37,10 +37,6 @@ int posix_memalign(
|
|||||||
|
|
||||||
*memptr = NULL;
|
*memptr = NULL;
|
||||||
|
|
||||||
if ( size == 0 ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( alignment < sizeof( void * ) ) {
|
if ( alignment < sizeof( void * ) ) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
@@ -49,6 +45,10 @@ int posix_memalign(
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( size == 0 ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
*memptr = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 );
|
*memptr = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 );
|
||||||
|
|
||||||
if ( *memptr == NULL ) {
|
if ( *memptr == NULL ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user