File: wrapper_forgets.rs

package info (click to toggle)
rust-bytemuck 1.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: makefile: 4
file content (13 lines) | stat: -rw-r--r-- 319 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
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);
}