Skip to content

Commit 45e7ba9

Browse files
committed
test more possible overaligned requests
1 parent 576369b commit 45e7ba9

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Diff for: src/liballoc/tests/heap.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::alloc::{Global, Alloc, Layout, System};
22

3-
/// Issue #45955.
3+
/// Issue #45955 and #62251.
44
#[test]
55
fn alloc_system_overaligned_request() {
66
check_overalign_requests(System)
@@ -12,21 +12,23 @@ fn std_heap_overaligned_request() {
1212
}
1313

1414
fn check_overalign_requests<T: Alloc>(mut allocator: T) {
15-
let size = 8;
16-
let align = 16; // greater than size
17-
let iterations = 100;
18-
unsafe {
19-
let pointers: Vec<_> = (0..iterations).map(|_| {
20-
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
21-
}).collect();
22-
for &ptr in &pointers {
23-
assert_eq!((ptr.as_ptr() as usize) % align, 0,
24-
"Got a pointer less aligned than requested")
25-
}
15+
for &align in &[4, 8, 16, 32] { // less than and bigger than `MIN_ALIGN`
16+
for &size in &[align/2, align-1] { // size less than alignment
17+
let iterations = 128;
18+
unsafe {
19+
let pointers: Vec<_> = (0..iterations).map(|_| {
20+
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
21+
}).collect();
22+
for &ptr in &pointers {
23+
assert_eq!((ptr.as_ptr() as usize) % align, 0,
24+
"Got a pointer less aligned than requested")
25+
}
2626

27-
// Clean up
28-
for &ptr in &pointers {
29-
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
27+
// Clean up
28+
for &ptr in &pointers {
29+
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
30+
}
31+
}
3032
}
3133
}
3234
}

0 commit comments

Comments
 (0)