1 #![feature(custom_attribute)]
2 #![allow(dead_code, unused_attributes)]
5 fn overwriting_part_of_relocation_makes_the_rest_undefined() -> i32 {
8 let ptr: *mut _ = &mut p;
9 *(ptr as *mut u32) = 123;
11 *p //~ ERROR: attempted to read undefined bytes
15 fn pointers_to_different_allocations_are_unorderable() -> bool {
16 let x: *const u8 = &1;
17 let y: *const u8 = &2;
18 x < y //~ ERROR: attempted to do math or a comparison on pointers into different allocations
22 fn invalid_bool() -> u8 {
23 let b = unsafe { std::mem::transmute::<u8, bool>(2) };
24 if b { 1 } else { 2 } //~ ERROR: invalid boolean value read
28 fn undefined_byte_read() -> u8 {
29 let v: Vec<u8> = Vec::with_capacity(10);
30 let undef = unsafe { *v.get_unchecked(5) };
31 undef + 1 //~ ERROR: attempted to read undefined bytes
35 fn out_of_bounds_read() -> u8 {
36 let v: Vec<u8> = vec![1, 2];
37 unsafe { *v.get_unchecked(5) } //~ ERROR: pointer offset outside bounds of allocation
41 fn dangling_pointer_deref() -> i32 {
46 unsafe { *p } //~ ERROR: dangling pointer was dereferenced