rust/tests/compile-fail/reallocate-change-alloc.rs
2018-06-05 18:08:18 +02:00

15 lines
365 B
Rust

#![feature(alloc, allocator_api)]
extern crate alloc;
use alloc::alloc::Global;
use std::alloc::*;
fn main() {
unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1));
let _y = Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
let _z = *(x as *mut u8); //~ ERROR: dangling pointer was dereferenced
}
}