@@ -863,10 +863,18 @@ mod verify {
863
863
use super :: * ;
864
864
865
865
// 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
866
874
#[ kani:: proof]
867
- #[ kani:: unwind( 32 ) ] // Proof bounded by array length
875
+ #[ kani:: unwind( 32 ) ]
868
876
fn check_from_bytes_until_nul_random_nul_byte ( ) {
869
- const ARR_LEN : usize = 1000 ;
877
+ const ARR_LEN : usize = 32 ;
870
878
let mut string: [ u8 ; ARR_LEN ] = kani:: any ( ) ;
871
879
872
880
// ensure that there is at least one null byte
@@ -878,10 +886,11 @@ mod verify {
878
886
}
879
887
880
888
#[ kani:: proof]
881
- #[ kani:: unwind( 32 ) ] // Proof bounded by array length
889
+ #[ kani:: unwind( 32 ) ]
882
890
fn check_from_bytes_until_nul_single_nul_byte_end ( ) {
883
- const ARR_LEN : usize = 1000 ;
891
+ const ARR_LEN : usize = 32 ;
884
892
// ensure that the string does not have intermediate null bytes
893
+ // TODO: there might be a better way
885
894
let mut string: [ u8 ; ARR_LEN ] = kani:: any_where ( |x : & [ u8 ; ARR_LEN ] | !x[ ..ARR_LEN -1 ] . contains ( & 0 ) ) ;
886
895
// ensure that the string is properly null-terminated
887
896
string[ ARR_LEN - 1 ] = 0 ;
@@ -891,9 +900,9 @@ mod verify {
891
900
}
892
901
893
902
#[ kani:: proof]
894
- #[ kani:: unwind( 8 ) ] // Proof bounded by array length
903
+ #[ kani:: unwind( 16 ) ]
895
904
fn check_from_bytes_until_nul_single_nul_byte_head ( ) {
896
- const ARR_LEN : usize = 8 ;
905
+ const ARR_LEN : usize = 16 ;
897
906
let mut string: [ u8 ; ARR_LEN ] = kani:: any ( ) ;
898
907
// The first byte is a null byte should result in an empty CStr.
899
908
string[ 0 ] = 0 ;
0 commit comments