diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-05-05 08:49:52 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-05-06 08:03:58 +0200 |
commit | 2c5199bb049efe8e29cd12461dc57bd6e30388e8 (patch) | |
tree | 31086387522ae9803a5a15bb33ee014ed96eeaf8 /cpukit/libcsupport/src/malloc.c | |
parent | libc: Reimplement posix_memlign() (diff) | |
download | rtems-2c5199bb049efe8e29cd12461dc57bd6e30388e8.tar.bz2 |
Return NULL for zero size allocations
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. Return NULL on RTEMS to more likely catch the use of a
zero size memory area by erroneous applications.
Update #4390.
Diffstat (limited to 'cpukit/libcsupport/src/malloc.c')
-rw-r--r-- | cpukit/libcsupport/src/malloc.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c index 795254fbab..3e55a94c83 100644 --- a/cpukit/libcsupport/src/malloc.c +++ b/cpukit/libcsupport/src/malloc.c @@ -30,6 +30,10 @@ void *malloc( { void *return_this; + if ( size == 0 ) { + return NULL; + } + return_this = rtems_heap_allocate_aligned_with_boundary( size, 0, 0 ); if ( !return_this ) { errno = ENOMEM; |