Description
The following snippet extracted from this crate failed under MIRI:
fn main() {
unsafe {
let mut piHashTable = vec![0i32; 10];
let mut pTable = &mut piHashTable[2] as *mut i32;
*pTable.offset(3) = 2 as i32;
}
}
error: Undefined Behavior: attempting a write access using <3294> at alloc1703[0x14], but that tag does not exist in the borrow stack for this location
--> src/main.rs:6:9
|
6 | *pTable.offset(3) = 2 as i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| attempting a write access using <3294> at alloc1703[0x14], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at alloc1703[0x14..0x18]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <3294> was created by a retag at offsets [0x8..0xc]
--> src/main.rs:5:26
|
5 | let mut pTable = &mut piHashTable[2] as *mut i32;
| ^^^^^^^^^^^^^^^^^^^
= note: insidemain
at src/main.rs:6:9
This was noticed as part of bevyengine/bevy#4932, an effort to rewrite this crate into idiomatic Rust. There may be other soundness issues; the autogenerated code uses a lot of pointless unsafe in strange ways.