Skip to content

Commit 657caf8

Browse files
test: fix test for OOM instead of overflow (#320)
1 parent 1db9be9 commit 657caf8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tests/all/tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ fn oom_instead_of_bump_pointer_overflow() {
7171
let x = bump.alloc(0_u8);
7272
let p = x as *mut u8 as usize;
7373

74+
// Prevent bump from allocating a new chunk.
75+
bump.set_allocation_limit(Some(bump.allocated_bytes()));
76+
7477
// A size guaranteed to overflow the bump pointer.
75-
let size = (isize::MAX as usize) - p + 1;
78+
// We assume that heap allocations are made in bottom half of address space, so `size < isize::MAX`.
79+
// If that assumption is incorrect, `Layout::from_size_align` will return `Err` and the test will fail.
80+
let size = p + 1;
7681
let align = 1;
7782
let layout = match Layout::from_size_align(size, align) {
7883
Err(e) => {

0 commit comments

Comments
 (0)