[rtems commit] Check the alignment in posix_memalign() earlier
Sebastian Huber
sebh at rtems.org
Fri May 7 05:08:41 UTC 2021
Module: rtems
Branch: master
Commit: c46d125569a215226602a7d4b9c346ee074fe365
Changeset: http://git.rtems.org/rtems/commit/?id=c46d125569a215226602a7d4b9c346ee074fe365
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu May 6 19:25:09 2021 +0200
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(-)
diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c
index 4e89413..418de99 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 ) {
More information about the vc
mailing list