mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Don't rely on Global handing out dangling pointers
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user