Skip to content

Commit

Permalink
Cstr - add proof from_bytes_with_null (#198)
Browse files Browse the repository at this point in the history
Towards #150 

Verifies that the CStr safety invariant holds after calling :

from_bytes_with_nul --> core::ffi::c_str module
  • Loading branch information
rajathkotyal authored Dec 3, 2024
1 parent db71987 commit ca85f7f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,20 @@ mod verify {
assert!(c_str.is_safe());
}
}


#[kani::proof]
#[kani::unwind(17)]
fn check_from_bytes_with_nul() {
const MAX_SIZE: usize = 16;
let string: [u8; MAX_SIZE] = kani::any();
let slice = kani::slice::any_slice_of_array(&string);

let result = CStr::from_bytes_with_nul(slice);
if let Ok(c_str) = result {
assert!(c_str.is_safe());
}
}

// pub const fn count_bytes(&self) -> usize
#[kani::proof]
#[kani::unwind(32)]
Expand Down Expand Up @@ -956,4 +969,4 @@ mod verify {
assert_eq!(expected_is_empty, c_str.is_empty());
assert!(c_str.is_safe());
}
}
}

0 comments on commit ca85f7f

Please sign in to comment.