check for overflow when doing pointer arithmetic

This commit is contained in:
Ralf Jung
2017-06-04 18:47:31 -07:00
parent 70227c87bf
commit f39e015163
10 changed files with 76 additions and 33 deletions

View File

@@ -0,0 +1,8 @@
//error-pattern: overflowing math on a pointer
fn main() {
let v = [1i8, 2];
let x = &v[1] as *const i8;
// One of them is guaranteed to overflow
let _ = unsafe { x.offset(isize::max_value()) };
let _ = unsafe { x.offset(isize::min_value()) };
}