diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-07-04 23:54:12 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-07-04 23:54:12 -0400 |
commit | 651416182dc65d75e91cadfec65dd72f9ff07846 (patch) | |
tree | 4f1a085a262cb195f1fab6a27b7f0335b35712fc /src/malloc | |
parent | ab724204393bcc990d519b1358f4ec3ee1f3a570 (diff) | |
download | musl-651416182dc65d75e91cadfec65dd72f9ff07846.tar.gz musl-651416182dc65d75e91cadfec65dd72f9ff07846.tar.bz2 musl-651416182dc65d75e91cadfec65dd72f9ff07846.tar.xz musl-651416182dc65d75e91cadfec65dd72f9ff07846.zip |
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.
Diffstat (limited to 'src/malloc')
-rw-r--r-- | src/malloc/aligned_alloc.c | 2 | ||||
-rw-r--r-- | src/malloc/posix_memalign.c | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/src/malloc/aligned_alloc.c b/src/malloc/aligned_alloc.c index 158dba41..c6386629 100644 --- a/src/malloc/aligned_alloc.c +++ b/src/malloc/aligned_alloc.c @@ -11,7 +11,7 @@ void *aligned_alloc(size_t align, size_t len) unsigned char *mem, *new, *end; size_t header, footer; - if ((align & -align & -sizeof(void *)) != align) { + if ((align & -align) != align) { errno = EINVAL; return NULL; } diff --git a/src/malloc/posix_memalign.c b/src/malloc/posix_memalign.c index 42cf2740..ad4d8f47 100644 --- a/src/malloc/posix_memalign.c +++ b/src/malloc/posix_memalign.c @@ -3,6 +3,7 @@ int posix_memalign(void **res, size_t align, size_t len) { + if (align < sizeof(void *)) return EINVAL; void *mem = aligned_alloc(align, len); if (!mem) return errno; *res = mem; |