rust/tests/compile-fail/uninit_buffer.rs

21 lines
543 B
Rust
Raw Normal View History

2020-05-14 08:03:49 -05:00
// error-pattern: 12 bytes are uninitialized
2020-04-23 20:00:25 -05:00
use std::alloc::{alloc, dealloc, Layout};
use std::slice::from_raw_parts;
fn main() {
let layout = Layout::from_size_align(32, 8).unwrap();
unsafe {
let ptr = alloc(layout);
*ptr = 0x41;
*ptr.add(1) = 0x42;
*ptr.add(2) = 0x43;
*ptr.add(3) = 0x44;
*ptr.add(16) = 0x00;
let slice1 = from_raw_parts(ptr, 16);
let slice2 = from_raw_parts(ptr.add(16), 16);
drop(slice1.cmp(slice2));
dealloc(ptr, layout);
}
}