Skip to content

Commit ca85f7f

Browse files
authored
Cstr - add proof from_bytes_with_null (rust-lang#198)
Towards rust-lang#150 Verifies that the CStr safety invariant holds after calling : from_bytes_with_nul --> core::ffi::c_str module
1 parent db71987 commit ca85f7f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

library/core/src/ffi/c_str.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,20 @@ mod verify {
885885
assert!(c_str.is_safe());
886886
}
887887
}
888-
888+
889+
#[kani::proof]
890+
#[kani::unwind(17)]
891+
fn check_from_bytes_with_nul() {
892+
const MAX_SIZE: usize = 16;
893+
let string: [u8; MAX_SIZE] = kani::any();
894+
let slice = kani::slice::any_slice_of_array(&string);
895+
896+
let result = CStr::from_bytes_with_nul(slice);
897+
if let Ok(c_str) = result {
898+
assert!(c_str.is_safe());
899+
}
900+
}
901+
889902
// pub const fn count_bytes(&self) -> usize
890903
#[kani::proof]
891904
#[kani::unwind(32)]
@@ -956,4 +969,4 @@ mod verify {
956969
assert_eq!(expected_is_empty, c_str.is_empty());
957970
assert!(c_str.is_safe());
958971
}
959-
}
972+
}

0 commit comments

Comments
 (0)