Skip to content

Commit

Permalink
Add tests for pointer overflow checking (rust-lang#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsn authored and tedinski committed Feb 2, 2022
1 parent 6ce9a04 commit 6720d44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/kani/Overflow/pointer_overflow_fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-verify-fail

pub fn main() {
let a = [0; 5];
let i: i32 = 0;
let ptr1: *const i32 = &a[0];
let ptr_overflow1 = unsafe { ptr1.offset(isize::MAX) };
}
14 changes: 14 additions & 0 deletions tests/kani/Overflow/pointer_overflow_fixme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-verify-fail
// This should fail, but doesn't due to https://github.com/diffblue/cbmc/issues/6631

pub fn main() {
let a = [0; 5];
let i: i32 = 0;
let ptr1: *const i32 = &a[1];
let ptr2: *const i32 = &i;
let ptr2 = unsafe { ptr2.offset(1) };
let ptr_overflow1 = unsafe { ptr1.offset(isize::MAX) };
let ptr_overflow2 = unsafe { ptr2.offset(isize::MAX) };
}

0 comments on commit 6720d44

Please sign in to comment.