Skip to content
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

Harnesses for count_bytes #191

Merged
merged 23 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bf613a0
Test CStr safety invariant
Yenyun035 Nov 22, 2024
cf6aab1
Merge branch 'model-checking:main' into c-0013-yenyunw-cstr
Yenyun035 Nov 22, 2024
63d53fb
Merge branch 'model-checking:main' into c-0013-yenyunw-cstr
Yenyun035 Nov 22, 2024
754baec
feat: add check_count_bytes
MWDZ Nov 22, 2024
90ae7a5
Add CStr safety invariant && from_bytes_until_null harnesses
Yenyun035 Nov 22, 2024
e111145
Merge branch 'model-checking:main' into c-0013-yenyunw-cstr
Yenyun035 Nov 22, 2024
55dfaaf
Add comments
Yenyun035 Nov 22, 2024
2d5b3f8
Merge branch 'c-0013-yenyunw-cstr' into c-0013-junfengj-cstr
MWDZ Nov 23, 2024
0cd92cb
feat: add check_count_bytes to c_str
MWDZ Nov 23, 2024
5db0f1b
Merge branch 'main' into c-0013-yenyunw-cstr
Yenyun035 Nov 23, 2024
31c1d02
Fix from_bytes_until_nul harness
Yenyun035 Nov 25, 2024
667b76f
Merge branch 'main' into c-0013-yenyunw-cstr
Yenyun035 Nov 25, 2024
64ddbff
Add to_bytes and to_bytes_with_nul harnesses
Yenyun035 Nov 27, 2024
03c5760
feat: adjust the length in check_count_bytes
MWDZ Nov 27, 2024
0c33a9f
Merge remote-tracking branch 'origin/c-0013-yenyunw-cstr' into c-0013…
MWDZ Nov 27, 2024
40f74f7
Merge remote-tracking branch 'origin/c-0013-yenyunw-cstr-to-bytes' in…
MWDZ Nov 27, 2024
24b3366
Merge branch 'main' into c-0013-junfengj-cstr
Yenyun035 Nov 27, 2024
1180af4
remove check_to_bytes and check_to_byte_with_null
MWDZ Nov 27, 2024
196ef41
Merge remote-tracking branch 'refs/remotes/origin/c-0013-junfengj-cst…
MWDZ Nov 27, 2024
07a7f9e
Merge branch 'main' into c-0013-junfengj-cstr
Yenyun035 Nov 27, 2024
1f56dc5
fix: fix the wording of `randomly`
MWDZ Nov 28, 2024
8d0b8aa
feat: change the wording string to bytes
MWDZ Nov 28, 2024
1767edb
Merge remote-tracking branch 'refs/remotes/origin/c-0013-junfengj-cst…
MWDZ Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,27 @@ mod verify {
assert!(c_str.is_safe());
}
}

#[kani::proof]
#[kani::unwind(32)]
fn check_count_bytes() {
const MAX_SIZE: usize = 32;
let mut bytes: [u8; MAX_SIZE] = kani::any();

// Non-deterministically generate a length within the valid range [0, MAX_SIZE]
let mut len: usize = kani::any_where(|&x| x < MAX_SIZE);

// If a null byte exists before the generated length
// adjust len to its position
if let Some(pos) = bytes[..len].iter().position(|&x| x == 0) {
len = pos;
} else {
// If no null byte, insert one at the chosen length
bytes[len] = 0;
}

let c_str = CStr::from_bytes_until_nul(&bytes).unwrap();
// Verify that count_bytes matches the adjusted length
assert_eq!(c_str.count_bytes(), len);
}
}
Loading