]> git.lizzy.rs Git - rust.git/commitdiff
test for negative offsets
authorRalf Jung <post@ralfj.de>
Sat, 17 Jul 2021 12:43:32 +0000 (14:43 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 20 Jul 2021 11:30:49 +0000 (13:30 +0200)
tests/compile-fail/intrinsics/out_of_bounds_ptr_3.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/intrinsics/out_of_bounds_ptr_3.rs b/tests/compile-fail/intrinsics/out_of_bounds_ptr_3.rs
new file mode 100644 (file)
index 0000000..cd0861e
--- /dev/null
@@ -0,0 +1,7 @@
+// error-pattern: pointer to 1 byte starting at offset -1 is out-of-bounds
+fn main() {
+    let v = [0i8; 4];
+    let x = &v as *const i8;
+    let x = unsafe { x.offset(-1) };
+    panic!("this should never print: {:?}", x);
+}