make sure that StorageDead invalidates the backing store
This commit is contained in:
parent
c2670bfdd8
commit
1538b36c80
20
tests/compile-fail/storage_dead_dangling.rs
Normal file
20
tests/compile-fail/storage_dead_dangling.rs
Normal file
@ -0,0 +1,20 @@
|
||||
static mut LEAK: usize = 0;
|
||||
|
||||
fn fill(v: &mut i32) {
|
||||
unsafe { LEAK = v as *mut _ as usize; }
|
||||
}
|
||||
|
||||
fn evil() {
|
||||
let v = unsafe { &mut *(LEAK as *mut i32) };
|
||||
let _x = *v; //~ ERROR dangling pointer was dereferenced
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _y;
|
||||
{
|
||||
let mut x = 0i32;
|
||||
fill(&mut x);
|
||||
_y = x;
|
||||
}
|
||||
evil();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user