summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-06 19:25:09 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-07 07:08:04 +0200
commitc46d125569a215226602a7d4b9c346ee074fe365 (patch)
tree16562825ff14178e4877491336d75536a4602ef8 /cpukit/libcsupport/src
parentbsps/shared/ofw: Fix coverity defects (diff)
downloadrtems-c46d125569a215226602a7d4b9c346ee074fe365.tar.bz2
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.
Diffstat (limited to 'cpukit/libcsupport/src')
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c8
1 files changed, 4 insertions, 4 deletions
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 ) {