Make zero size allocation result consistent

The zero size allocations had no consistent behaviour in RTEMS.  For
example, malloc( 0 ) returned NULL and posix_memalign( &p, align, 0 )
returned in p a unique pointer (or NULL if no memory is available).  In
POSIX, zero size memory allocations are implementation-defined
behaviour.  The implementation has two options:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html

https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html

Linux and FreeBSD return a unique pointer for zero size memory
allocations.   Use this approach for RTEMS as well throughout the memory
allocation directives

Close #4390.
This commit is contained in:
Sebastian Huber
2021-05-04 09:37:06 +02:00
parent eb7c33add0
commit d692c62dfb
4 changed files with 100 additions and 24 deletions
-6
View File
@@ -30,12 +30,6 @@ void *malloc(
{
void *return_this;
/*
* Validate the parameters
*/
if ( !size )
return (void *) 0;
return_this = rtems_heap_allocate_aligned_with_boundary( size, 0, 0 );
if ( !return_this ) {
errno = ENOMEM;