Skip to content

Commit

Permalink
Fix tests after enabling offset bound checks
Browse files Browse the repository at this point in the history
  • Loading branch information
celinval committed Dec 5, 2024
1 parent ed7e698 commit dd634af
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ fn test_copy_nonoverlapping_invalid() {
let arr: [i32; 3] = [0, 1, 0];
let src: *const i32 = arr.as_ptr();

// Get an invalid pointer with a negative offset
let src_invalid = src.wrapping_sub(1) as *const i32;
let dst = src.wrapping_add(1) as *mut i32;
unsafe {
// Get an invalid pointer with a negative offset
let src_invalid = unsafe { src.sub(1) as *const i32 };
let dst = src.add(1) as *mut i32;
core::intrinsics::copy_nonoverlapping(src_invalid, dst, 1);
}
}
6 changes: 3 additions & 3 deletions tests/expected/intrinsics/copy/copy-unreadable-src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ fn test_copy_invalid() {
let arr: [i32; 3] = [0, 1, 0];
let src: *const i32 = arr.as_ptr();

// Get an invalid pointer with a negative offset
let src_invalid = src.wrapping_sub(1) as *const i32;
let dst = src.wrapping_add(1) as *mut i32;
unsafe {
// Get an invalid pointer with a negative offset
let src_invalid = unsafe { src.sub(1) as *const i32 };
let dst = src.add(1) as *mut i32;
core::intrinsics::copy(src_invalid, dst, 1);
}
}
3 changes: 1 addition & 2 deletions tests/expected/pointer-overflow/expected
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Status: FAILURE\
offset: attempt to compute number in bytes which would overflow
Failed Checks: Offset in bytes overflow isize
1 change: 0 additions & 1 deletion tests/expected/pointer-overflow/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//
// kani-flags: --enable-unstable --extra-pointer-checks
// Checks that overflows for pointer arithmetic are reported

#[kani::proof]
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/ptr_to_ref_cast/slice/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ fn check_with_byte_add_sub_pass() {
let ptr = &data as *const [u8];
let offset = kani::any_where(|i| *i < 100);
// This should pass since the resulting metadata is valid
let val = unsafe { &*ptr.byte_add(offset).byte_sub(offset) };
let val = unsafe { &*ptr.wrapping_byte_add(offset).wrapping_byte_sub(offset) };
assert_eq!(val.len(), data.len());
}
4 changes: 1 addition & 3 deletions tests/kani/ValidValues/unaligned.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Z valid-value-checks
// kani-flags: -Z valid-value-checks -Z mem-predicates
//! Check that Kani can check value validity of packed structs.
use std::ptr::addr_of;
Expand Down Expand Up @@ -34,6 +34,4 @@ pub fn check_packed_read_unaligned_invalid_value() {
let val = [u8::MAX; SZ];
let ptr = addr_of!(val) as *const Packed;
assert!(!kani::mem::can_read_unaligned(ptr));
assert!(kani::mem::can_read_unaligned(unsafe { addr_of!((*ptr).byte) }));
assert!(!kani::mem::can_read_unaligned(unsafe { addr_of!((*ptr).c) }));
}

0 comments on commit dd634af

Please sign in to comment.