Skip to content

Commit

Permalink
test: add test case cannot_alloc_max_usize_minus_some
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Sep 12, 2021
1 parent cc72c24 commit 77b0c40
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/rlsf/tests/global.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Adopted from
// https://github.com/alexcrichton/dlmalloc-rs/blob/master/tests/global.rs
use std::collections::HashMap;
use std::{
alloc::{GlobalAlloc, Layout},
collections::HashMap,
};

#[global_allocator]
#[cfg(any(all(target_arch = "wasm32", not(target_feature = "atomics")), unix))]
Expand Down Expand Up @@ -52,3 +55,15 @@ fn test_larger_than_word_alignment() {
}
}
}

#[test]
fn cannot_alloc_max_usize_minus_some() {
// The test should complete without causing OOM
for offset in (0..64).step_by(8) {
let layout = Layout::from_size_align(usize::MAX - offset, 1).unwrap();
for _ in 0..1000000 {
let result = unsafe { A.alloc(layout) };
assert!(result.is_null());
}
}
}

0 comments on commit 77b0c40

Please sign in to comment.