Don't rely on Global handing out dangling pointers

This commit is contained in:
Max Dexheimer
2026-10-09 14:49:47 +02:00
parent 8d1a764304
commit eece26e9a7

View File

@@ -248,6 +248,9 @@ pub struct Box<
#[cfg(not(no_global_oom_handling))]
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
const fn box_new_uninit(layout: Layout) -> *mut u8 {
if layout.size() == 0 {
return layout.dangling_ptr().as_ptr();
}
match Global.allocate(layout) {
Ok(ptr) => ptr.as_mut_ptr(),
Err(_) => handle_alloc_error(layout),