Skip to content

Commit 0641d5b

Browse files
committed
0-offset is also not always okay
1 parent edf28fa commit 0641d5b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// error-pattern: outside bounds of allocation
2+
3+
fn main() {
4+
let x = Box::into_raw(Box::new(0u32));
5+
let x = x.wrapping_offset(8); // okay, this has no inbounds tag
6+
let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is not inbounds of the only object it can point to
7+
}

0 commit comments

Comments
 (0)