mirror of
https://github.com/fluencelabs/musl
synced 2025-06-14 15:31:42 +00:00
move alignment check from aligned_alloc to posix_memalign
C11 has no requirement that the alignment be a multiple of sizeof(void*), and in fact seems to require any "valid alignment supported by the implementation" to work. since the alignment of char is 1 and thus a valid alignment, an alignment argument of 1 should be accepted.
This commit is contained in:
@ -11,7 +11,7 @@ void *aligned_alloc(size_t align, size_t len)
|
|||||||
unsigned char *mem, *new, *end;
|
unsigned char *mem, *new, *end;
|
||||||
size_t header, footer;
|
size_t header, footer;
|
||||||
|
|
||||||
if ((align & -align & -sizeof(void *)) != align) {
|
if ((align & -align) != align) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
int posix_memalign(void **res, size_t align, size_t len)
|
int posix_memalign(void **res, size_t align, size_t len)
|
||||||
{
|
{
|
||||||
|
if (align < sizeof(void *)) return EINVAL;
|
||||||
void *mem = aligned_alloc(align, len);
|
void *mem = aligned_alloc(align, len);
|
||||||
if (!mem) return errno;
|
if (!mem) return errno;
|
||||||
*res = mem;
|
*res = mem;
|
||||||
|
Reference in New Issue
Block a user