summaryrefslogtreecommitdiff
path: root/libc/stdlib
diff options
context:
space:
mode:
authorKito Cheng <kito.cheng@gmail.com>2017-02-23 17:16:28 +0800
committerWaldemar Brodkorb <wbx@openadk.org>2017-02-25 02:41:28 +0100
commit058c263f6bd41ffa18328e0ff60d25d3a028f975 (patch)
treea2fe4d2b0a063a3886b87f0825c31d2041e7fd1e /libc/stdlib
parentdeccf064840d9719bc5b022fe7ffaf9b9c2147da (diff)
Only set *memptr when success for posix_memalign
Diffstat (limited to 'libc/stdlib')
-rw-r--r--libc/stdlib/posix_memalign.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libc/stdlib/posix_memalign.c b/libc/stdlib/posix_memalign.c
index 523bc2cbd..01831070f 100644
--- a/libc/stdlib/posix_memalign.c
+++ b/libc/stdlib/posix_memalign.c
@@ -34,8 +34,10 @@ int posix_memalign(void **memptr, size_t alignment, size_t size)
|| alignment == 0
*/
return EINVAL;
-
- *memptr = memalign(alignment, size);
-
- return (*memptr != NULL ? 0 : ENOMEM);
+ void *mem = memalign(alignment, size);
+ if (mem != NULL) {
+ *memptr = mem;
+ return 0;
+ } else
+ return ENOMEM;
}