diff options
author | daan <daanl@outlook.com> | 2019-09-11 17:49:28 -0700 |
---|---|---|
committer | daan <daanl@outlook.com> | 2019-09-11 17:49:28 -0700 |
commit | 24777f6a9116d51a1ba6f79e619bedeef3b4d06f (patch) | |
tree | 664808885f77dd294d23fd034b2f20bbea6b62e2 /src/alloc-posix.c | |
parent | 050e7cedf453e05eb4e498786b467b599a154f9b (diff) |
limit aligned allocation to power-of-two alignment
Diffstat (limited to 'src/alloc-posix.c')
-rw-r--r-- | src/alloc-posix.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/alloc-posix.c b/src/alloc-posix.c index f64cb1f..505e42e 100644 --- a/src/alloc-posix.c +++ b/src/alloc-posix.c @@ -71,7 +71,8 @@ void* mi_pvalloc(size_t size) mi_attr_noexcept { } void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept { - if (alignment != 0 && (size%alignment) != 0) return NULL; // C11 required; <https://en.cppreference.com/w/c/memory/aligned_alloc> + if (alignment==0 || !_mi_is_power_of_two(alignment)) return NULL; + if ((size&(alignment-1)) != 0) return NULL; // C11 requires integral multiple, see <https://en.cppreference.com/w/c/memory/aligned_alloc> return mi_malloc_aligned(size, alignment); } |