Fix/remove flawed alignment-related overflow tests.

Fix/remove three related flawed tests that attempted to cause OOM due to
large request size and alignment constraint.  Although these tests
"passed" on 64-bit systems due to the virtual memory hole, they could
pass on some 32-bit systems.
This commit is contained in:
Jason Evans 2014-01-28 18:02:07 -08:00
parent 2b51a3e9e9
commit a184d3fcde
3 changed files with 4 additions and 25 deletions

View File

@ -47,10 +47,10 @@ TEST_BEGIN(test_oom_errors)
#if LG_SIZEOF_PTR == 3 #if LG_SIZEOF_PTR == 3
alignment = UINT64_C(0x4000000000000000); alignment = UINT64_C(0x4000000000000000);
size = UINT64_C(0x8400000000000001); size = UINT64_C(0xc000000000000001);
#else #else
alignment = 0x40000000LU; alignment = 0x40000000LU;
size = 0x84000001LU; size = 0xc0000001LU;
#endif #endif
set_errno(0); set_errno(0);
p = aligned_alloc(alignment, size); p = aligned_alloc(alignment, size);

View File

@ -34,26 +34,6 @@ TEST_BEGIN(test_basic)
} }
TEST_END TEST_END
TEST_BEGIN(test_alignment_errors)
{
void *p;
size_t nsz, sz, alignment;
#if LG_SIZEOF_PTR == 3
alignment = UINT64_C(0x4000000000000000);
sz = UINT64_C(0x8400000000000001);
#else
alignment = 0x40000000LU;
sz = 0x84000001LU;
#endif
nsz = nallocx(sz, MALLOCX_ALIGN(alignment));
assert_zu_ne(nsz, 0, "Unexpected nallocx() error");
p = mallocx(sz, MALLOCX_ALIGN(alignment));
assert_ptr_null(p, "Expected error for mallocx(%zu, %#x)", sz,
MALLOCX_ALIGN(alignment));
}
TEST_END
TEST_BEGIN(test_alignment_and_size) TEST_BEGIN(test_alignment_and_size)
{ {
size_t nsz, rsz, sz, alignment, total; size_t nsz, rsz, sz, alignment, total;
@ -114,6 +94,5 @@ main(void)
return (test( return (test(
test_basic, test_basic,
test_alignment_errors,
test_alignment_and_size)); test_alignment_and_size));
} }

View File

@ -43,10 +43,10 @@ TEST_BEGIN(test_oom_errors)
#if LG_SIZEOF_PTR == 3 #if LG_SIZEOF_PTR == 3
alignment = UINT64_C(0x4000000000000000); alignment = UINT64_C(0x4000000000000000);
size = UINT64_C(0x8400000000000001); size = UINT64_C(0xc000000000000001);
#else #else
alignment = 0x40000000LU; alignment = 0x40000000LU;
size = 0x84000001LU; size = 0xc0000001LU;
#endif #endif
assert_d_ne(posix_memalign(&p, alignment, size), 0, assert_d_ne(posix_memalign(&p, alignment, size), 0,
"Expected error for posix_memalign(&p, %zu, %zu)", "Expected error for posix_memalign(&p, %zu, %zu)",