rust/tests/compile-fail/reallocate-dangling.rs

17 lines
428 B
Rust
Raw Normal View History

2019-04-14 03:30:00 -05:00
#![feature(allocator_api)]
extern crate alloc;
2018-05-09 08:54:45 -05:00
use alloc::alloc::Global;
use std::alloc::{AllocRef, Layout};
// error-pattern: dangling pointer was dereferenced
fn main() {
unsafe {
2020-03-04 02:50:26 -06:00
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
2018-05-09 08:54:45 -05:00
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
}
}