From cf26458376f47c659c663b1735c395a94a475e5f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 17 Jul 2021 14:43:32 +0200 Subject: [PATCH] test for negative offsets --- tests/compile-fail/intrinsics/out_of_bounds_ptr_3.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/compile-fail/intrinsics/out_of_bounds_ptr_3.rs 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 index 00000000000..cd0861efe5d --- /dev/null +++ b/tests/compile-fail/intrinsics/out_of_bounds_ptr_3.rs @@ -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); +}