-
In our discussion with @zhassan-aws, we are trying to use use crate::alloc::{self, Layout}; // use crate::alloc::{Layout, alloc, dealloc} result in error saying alloc and dealloc are not found
// pub const unsafe fn add(self, count: usize) -> Self
#[kani::proof_for_contract(NonNull::add)]
pub fn non_null_check_add() {
let size: usize = kani::any();
let layout = Layout::array::<i8>(size).unwrap();
let raw_ptr = unsafe { alloc(self, layout) as *mut i8 };
// NonNull pointer to the random offset
let ptr = unsafe { NonNull::new(raw_ptr).unwrap()};
// Create a non-deterministic count value
let count: usize = kani::any();
// Workaround: SAFETY: Ensure that the pointer operation does not go out of the bounds of the array
kani::assume(count < size);
unsafe {
// Add a positive offset to pointer
let result = ptr.add(count);
dealloc(self, raw_ptr as *mut u8, layout);
}
} But received the following compilation error starting with:
Appreciate any suggestion on how to potentially resolve these errors. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @QinyuanWu, since the code you are trying to verify ( Another possibility is to use the new |
Beta Was this translation helpful? Give feedback.
-
@QinyuanWu my bad. @celinval my suggestion to use |
Beta Was this translation helpful? Give feedback.
Hi @QinyuanWu, since the code you are trying to verify (
NonNull
) is part of thecore
crate, you cannot use dynamic allocation. In this case, I would recommend that you use a fixed array size, and an index variable with non-deterministic value that is less than length to cover different scenarios.Another possibility is to use the new
PointerGenerator
that we recently added to Kani.