forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid undefined behavior in AnySlice::new() (model-checking#2288)
Signed-off-by: Felipe R. Monteiro <[email protected]>
- Loading branch information
1 parent
878e5b9
commit 4b925fd
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Assigning to a memory location via pointer dereferencing causes Drop::drop to be called for the location to which the pointer points. | ||
// Here, kani::Arbitrary implementation for MyStruct deterministically sets MyStruct.0 to 1. | ||
// We check whether AnySlice will properly initialize memory making the assertion in drop() to pass. | ||
|
||
struct MyStruct(i32); | ||
|
||
impl Drop for MyStruct { | ||
fn drop(&mut self) { | ||
assert!(self.0 == 1); | ||
} | ||
} | ||
|
||
impl kani::Arbitrary for MyStruct { | ||
fn any() -> Self { | ||
MyStruct(1) | ||
} | ||
} | ||
|
||
#[kani::proof] | ||
fn my_proof() { | ||
let my_slice = kani::slice::any_slice::<MyStruct, 1>(); | ||
} |