diff options
author | Christopher Ferris <cferris@google.com> | 2019-03-01 16:40:59 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2019-03-01 23:56:23 -0800 |
commit | a22f5d5175df5c42ec86d2c2db250edf1f64084c (patch) | |
tree | 66d2980a1b04626c7e4fc1437e96194b958ea8f8 /tests/stdlib_test.cpp | |
parent | 0771b752f1b955e7ded6ccbbf825b0ae93439eb5 (diff) |
Make aligned_alloc match the standard.
Jemalloc does not verify that the size parameter is a multiple of
alignment. Fix this since it only went into P.
Fix the unit tests, and fix malloc debug/malloc hooks to handle this
new restrictive behavior.
Bug: 126944692
Test: Ran bionic unit tests.
Test: Ran bionic unit tests with malloc hooks enabled (no new tests fail).
Test: Ran bionic unit tests with malloc debug enabled (no new tests fail).
Test: Ran malloc debug unit tests.
Change-Id: I4d50785928815679c781ca729f998454d76b9192
Diffstat (limited to 'tests/stdlib_test.cpp')
-rw-r--r-- | tests/stdlib_test.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 408a9c704..ff4cb71ee 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -272,11 +272,11 @@ TEST(stdlib, aligned_alloc_sweep) { for (size_t align = 1; align <= 2048; align <<= 1) { // Try all of the non power of 2 values from the last until this value. for (size_t fail_align = last_align + 1; fail_align < align; fail_align++) { - ASSERT_TRUE(aligned_alloc(fail_align, 256) == nullptr) + ASSERT_TRUE(aligned_alloc(fail_align, fail_align) == nullptr) << "Unexpected success at align " << fail_align; ASSERT_EQ(EINVAL, errno) << "Unexpected errno at align " << fail_align; } - void* ptr = aligned_alloc(align, 256); + void* ptr = aligned_alloc(align, 2 * align); ASSERT_TRUE(ptr != nullptr) << "Unexpected failure at align " << align; ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) << "Did not return a valid aligned ptr " << ptr << " expected alignment " << align; @@ -292,11 +292,11 @@ TEST(stdlib, aligned_alloc_overflow) { TEST(stdlib, aligned_alloc_size_not_multiple_of_alignment) { SKIP_WITH_HWASAN; - for (size_t size = 1; size <= 2048; size++) { - void* ptr = aligned_alloc(2048, size); - ASSERT_TRUE(ptr != nullptr) << "Failed at size " << std::to_string(size); - free(ptr); - } + + ASSERT_TRUE(aligned_alloc(2048, 1) == nullptr); + ASSERT_TRUE(aligned_alloc(4, 3) == nullptr); + ASSERT_TRUE(aligned_alloc(4, 7) == nullptr); + ASSERT_TRUE(aligned_alloc(16, 8) == nullptr); } TEST(stdlib, realpath__NULL_filename) { |