2019-05-26 07:47:37 -05:00
|
|
|
use std::ptr;
|
|
|
|
|
2017-06-04 20:47:31 -05:00
|
|
|
fn main() {
|
|
|
|
let v = [1i16, 2];
|
2019-05-26 07:47:37 -05:00
|
|
|
let x = &mut ptr::null(); // going through memory as there are more sanity checks along that path
|
|
|
|
*x = v.as_ptr().wrapping_offset(1); // ptr to the 2nd element
|
2017-06-04 20:47:31 -05:00
|
|
|
// Adding 2*isize::max and then 1 is like substracting 1
|
2019-05-26 07:47:37 -05:00
|
|
|
*x = x.wrapping_offset(isize::max_value());
|
|
|
|
*x = x.wrapping_offset(isize::max_value());
|
|
|
|
*x = x.wrapping_offset(1);
|
|
|
|
assert_eq!(unsafe { **x }, 1);
|
2017-06-04 20:47:31 -05:00
|
|
|
}
|