-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added harnesses for c_str: is_empty #195
Conversation
…ints' into c-0011-core-nums-junfengj-unchecked-shl
…nums-lanfeima-unsafe-ints
…to c-0013-lanfeima-cstr
Duplicate with #194. Will resolve later. |
I see that PR #194 takes an efficient approach by leveraging Would it make sense to address invalid cases elsewhere, or should we focus solely on valid instances here? Feedback from reviewers would be helpful. I’d be happy to close this PR or contribute to refining #194 if needed. Thank you! |
Can we merge the ideas by optimizing the |
@celinval If I understand correctly, do you mean that we ensure the input slice is null-terminated before passing it to fn arbitrary_cstr(slice: &[u8]) -> &CStr {
// At a minimum, the slice contains a null byte to form a valid CStr.
kani::assume(slice.len() > 0 && slice[slice.len() - 1] == 0);
let result = CStr::from_bytes_until_nul(&slice);
// Given the assumption, from_bytes_until_nul should never fail
kani::assume(result.is_ok()); // maybe change to assert!(result.is_ok());
let c_str = result.unwrap();
assert!(c_str.is_safe());
c_str
} I updated PR#194 accordingly. |
Closing per #195 (comment). |
Update:
I noticed that PR #194 leverages
arbitrary_cstr
(introduced in #189) to simplify the harnessCStr::is_empty
. Please also check that PR for additional context.Towards: Issue #150
Parent branch: main
Changes
This version of C
To revalidate the verification results, run
./scripts/run-kani.sh --kani-args --harness ffi::c_str::verify::check_is_empty
Example output:
Checking harness ffi::c_str::verify::check_is_empty... VERIFICATION RESULT: ** 0 of 216 failed (5 unreachable) VERIFICATION:- SUCCESSFUL Verification Time: 1121.6111s Complete - 1 successfully verified harnesses, 0 failures, 1 total.