diff options
author | Daan <daanl@outlook.com> | 2021-12-15 16:32:26 -0800 |
---|---|---|
committer | Daan <daanl@outlook.com> | 2021-12-15 16:32:26 -0800 |
commit | 9fbf83c4332da1cd1b788a7592d0f80ca52c6b1b (patch) | |
tree | 27ef958efb89954d54bc9b3e7b1a0fa3dfdc724b /src/alloc-posix.c | |
parent | 438595e693448c5853ff91a516105f1608637bf4 (diff) |
fix reallocarr indirection (see #492)
Diffstat (limited to 'src/alloc-posix.c')
-rw-r--r-- | src/alloc-posix.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/alloc-posix.c b/src/alloc-posix.c index 6627d2b..2eaede0 100644 --- a/src/alloc-posix.c +++ b/src/alloc-posix.c @@ -92,27 +92,23 @@ mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_n void* mi_reallocarray( void* p, size_t count, size_t size ) mi_attr_noexcept { // BSD void* newp = mi_reallocn(p,count,size); - if (newp==NULL) errno = ENOMEM; + if (newp==NULL) { errno = ENOMEM; } return newp; } int mi_reallocarr( void* p, size_t count, size_t size ) mi_attr_noexcept { // NetBSD - void** op = (void** )p; - int serrno = errno; - void* newp = mi_reallocn(p,count,size); - if (mi_unlikely(newp == NULL)) { - errno = ENOMEM; - return errno; - } else { - *op = newp; - errno = serrno; - return 0; - } + mi_assert(p != NULL); + if (p == NULL) return EINVAL; // should we set errno as well? + void** op = (void**)p; + void* newp = mi_reallocarray(*op, count, size); + if (mi_unlikely(newp == NULL)) return errno; + *op = newp; + return 0; } void* mi__expand(void* p, size_t newsize) mi_attr_noexcept { // Microsoft void* res = mi_expand(p, newsize); - if (res == NULL) errno = ENOMEM; + if (res == NULL) { errno = ENOMEM; } return res; } |