fn test() -> *const Vec<u8> {
let b = vec![9_u8];
let ret: *const Vec<u8> = &b;
println!("ret ptr={:#p} inside {:#p}", ret, b.as_ptr());
std::mem::forget(b);
ret
}
fn main() {
let a = test();
let v = unsafe {
&*a
};
println!("ret ptr={:#p} inside {:#p} value={}", v, v.as_ptr(), v[0]);
println!("ret ptr={:#p} inside {:#p} value={}", v, v.as_ptr(), v[0]);
}
im my machine this gives:
ret ptr=0x00007fffc5d85690 inside 0x00005650a61cfaa0
ret ptr=0x00007fffc5d85690 inside 0x00005650a61cfaa0 value=9
ret ptr=0x00007fffc5d85690 inside 0x00005650a572a348 value=76
the problem in the last line where the value changes suddenly, is this some kind of bug ?