Fix posix_memalign with input size 0.

Return a valid pointer instead of failed assertion.
This commit is contained in:
Qi Wang
2019-07-16 14:35:53 -07:00
committed by Qi Wang
parent a2a693e722
commit f32f23d6cc
2 changed files with 20 additions and 7 deletions

View File

@@ -85,9 +85,10 @@ TEST_BEGIN(test_alignment_and_size) {
alignment <= MAXALIGN;
alignment <<= 1) {
total = 0;
for (size = 1;
for (size = 0;
size < 3 * alignment && size < (1U << 31);
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
size += ((size == 0) ? 1 :
(alignment >> (LG_SIZEOF_PTR-1)) - 1)) {
for (i = 0; i < NITER; i++) {
err = posix_memalign(&ps[i],
alignment, size);