Skip to content

Commit 959693f

Browse files
committed
ensure that we cannot use (wrapping_)offset to go from an int ptr to a real ptr
1 parent 317f905 commit 959693f

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 = &mut *Box::new(0u32) as *mut u32;
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 = &mut *Box::new(0u32) as *mut u32;
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)