Merge pull request #590 from RalfJung/check-bounds

add test for offseting fn ptr
This commit is contained in:
Ralf Jung 2018-12-26 17:43:51 +01:00 committed by GitHub
commit 003febb584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,16 @@
fn f() -> i32 { 42 }
fn main() {
let v = [1i16, 2];
let x = &v as *const i16;
let x = unsafe { x.offset(1) };
assert_eq!(unsafe { *x }, 2);
// fn ptr offset
unsafe {
let p = f as fn() -> i32 as usize;
let x = (p as *mut u32).offset(0) as usize;
let f: fn() -> i32 = std::mem::transmute(x);
assert_eq!(f(), 42);
}
}