This repository was archived by the owner on Aug 25, 2025. It is now read-only.
  
  
  
  
  
Description
Describe the Bug
Allocating usize::MAX - 8 bytes fails but allocates new memory pages every time.
Steps to Reproduce
#[test]
fn cannot_alloc_max_usize_m8() {
    let a = &wee_alloc::WeeAlloc::INIT;
    let layout = Layout::from_size_align(std::usize::MAX - 8, 1)
        .expect("should be able to create a `Layout` with size = std::usize::MAX - 8");
    for _ in 0..10000000 {
        let result = unsafe { a.alloc(layout) };
        assert!(result.is_err());
    }
} 
Expected Behavior
The test should complete without causing OOM.
Actual Behavior
With debug assertions: thread 'cannot_alloc_max_usize_m8' panicked at 'attempt to add with overflow', .../.cargo/registry/src/github.com-1ecc6299db9ec823/memory_units-0.4.0/src/lib.rs:166:1
Without debug assertions: The test allocates tens of gigabytes of memory and eventually gets killed by the kernel.