Skip to content

Commit e058baf

Browse files
authored
Merge pull request #469 from RalfJung/ptr-offset
ensure that we cannot use (wrapping_)offset to go from an int ptr to a real ptr
2 parents 317f905 + 59eb3db commit e058baf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// error-pattern: pointer value as raw bytes
2+
3+
fn main() {
4+
let ptr = Box::into_raw(Box::new(0u32));
5+
// Can't start with an integer pointer and get to something usable
6+
unsafe {
7+
let _ = (1 as *mut u8).offset(ptr as isize);
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// error-pattern: pointer value as raw bytes
2+
3+
fn main() {
4+
let ptr = Box::into_raw(Box::new(0u32));
5+
// Can't start with an integer pointer and get to something usable
6+
let ptr = (1 as *mut u8).wrapping_offset(ptr as isize);
7+
let _ = unsafe { *ptr };
8+
}

0 commit comments

Comments
 (0)