mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-08 00:09:31 +03:00
Return EINVAL when alignment is not a power of 2
Consider to match the standard of posix, added a check of power of 2 to alignment in posix_memalign. Since, the check of multiple of sizeof(void*) contains the check of 0. I just check if alignment is a power of 2 behind without consider the condition it is 0. Splited the line to 2 for it is too long.
This commit is contained in:
parent
5dfced26c2
commit
298b829d5a
1 changed files with 2 additions and 4 deletions
|
@ -132,10 +132,8 @@ size_t malloc_usable_size(void *p) MI_FORWARD1(mi_usable_size,p)
|
||||||
void cfree(void* p) MI_FORWARD0(mi_free, p)
|
void cfree(void* p) MI_FORWARD0(mi_free, p)
|
||||||
|
|
||||||
int posix_memalign(void** p, size_t alignment, size_t size) {
|
int posix_memalign(void** p, size_t alignment, size_t size) {
|
||||||
// TODO: the spec says we should return EINVAL also if alignment is not a power of 2.
|
if ((alignment % sizeof(void*) != 0 ) &&
|
||||||
// The spec also dictates we should not modify `*p` on an error. (issue#27)
|
((alignment & (~alignment + 1)) == alignment)) return EINVAL; // no `p==NULL` check as it is declared as non-null
|
||||||
// <http://man7.org/linux/man-pages/man3/posix_memalign.3.html>
|
|
||||||
if (alignment % sizeof(void*) != 0) return EINVAL; // no `p==NULL` check as it is declared as non-null
|
|
||||||
void* q = mi_malloc_aligned(size, alignment);
|
void* q = mi_malloc_aligned(size, alignment);
|
||||||
if (q==NULL && size != 0) return ENOMEM;
|
if (q==NULL && size != 0) return ENOMEM;
|
||||||
*p = q;
|
*p = q;
|
||||||
|
|
Loading…
Add table
Reference in a new issue