Skip to content

Commit 55dfaaf

Browse files
committed
Add comments
1 parent e111145 commit 55dfaaf

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

library/core/src/ffi/c_str.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,18 @@ mod verify {
863863
use super::*;
864864

865865
// pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError>
866+
// Check 1: A random index in a u8 array is guaranteed to be a null byte
867+
// Check 2: Only the last byte of a u8 array is a null byte
868+
// Check 3: The first byte of a u8 array is a null byte
869+
//
870+
// Proofs are bounded (kani::unwind) by the length of the input array.
871+
// Check 1: 2.08 sec when 32; 7.49 sec when 40
872+
// Check 2: 6.72 sec when 32; 9.2 sec when 40
873+
// Check 3: 0.33 sec when 8; 2.06 sec when 16
866874
#[kani::proof]
867-
#[kani::unwind(32)] // Proof bounded by array length
875+
#[kani::unwind(32)]
868876
fn check_from_bytes_until_nul_random_nul_byte() {
869-
const ARR_LEN: usize = 1000;
877+
const ARR_LEN: usize = 32;
870878
let mut string: [u8; ARR_LEN] = kani::any();
871879

872880
// ensure that there is at least one null byte
@@ -878,10 +886,11 @@ mod verify {
878886
}
879887

880888
#[kani::proof]
881-
#[kani::unwind(32)] // Proof bounded by array length
889+
#[kani::unwind(32)]
882890
fn check_from_bytes_until_nul_single_nul_byte_end() {
883-
const ARR_LEN: usize = 1000;
891+
const ARR_LEN: usize = 32;
884892
// ensure that the string does not have intermediate null bytes
893+
// TODO: there might be a better way
885894
let mut string: [u8; ARR_LEN] = kani::any_where(|x: &[u8; ARR_LEN]| !x[..ARR_LEN-1].contains(&0));
886895
// ensure that the string is properly null-terminated
887896
string[ARR_LEN - 1] = 0;
@@ -891,9 +900,9 @@ mod verify {
891900
}
892901

893902
#[kani::proof]
894-
#[kani::unwind(8)] // Proof bounded by array length
903+
#[kani::unwind(16)]
895904
fn check_from_bytes_until_nul_single_nul_byte_head() {
896-
const ARR_LEN: usize = 8;
905+
const ARR_LEN: usize = 16;
897906
let mut string: [u8; ARR_LEN] = kani::any();
898907
// The first byte is a null byte should result in an empty CStr.
899908
string[0] = 0;

0 commit comments

Comments
 (0)