bytemuck/tests/wrapper_forgets.rs
Christopher Durham 1a4c11a675
Replace unsound usage of transmute_copy (#72)
* Use transmute! to enforce safer transmute_copy use

* Test fix for #71
2021-07-22 23:12:56 -06:00

14 lines
306 B
Rust

use bytemuck::TransparentWrapper;
#[repr(transparent)]
struct Wrap(Box<u32>);
// SAFETY: it's #[repr(transparent)]
unsafe impl TransparentWrapper<Box<u32>> for Wrap {}
fn main() {
let value = Box::new(5);
// This used to duplicate the wrapped value, creating a double free :(
Wrap::wrap(value);
}