Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- added Kani verification harnesses for `Bytes::pop_front` and `Bytes::pop_back`
- avoid flushing empty memory maps in `Section::freeze` to prevent macOS errors
- derived zerocopy traits for `SectionHandle` to allow storing handles in `ByteArea` sections
- added example demonstrating `ByteArea` with multiple typed sections, concurrent mutations, and freezing or persisting the area
Expand Down
34 changes: 34 additions & 0 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,40 @@ mod verification {
assert_eq!(bytes.as_ref(), copy.as_ref());
}

#[kani::proof]
#[kani::unwind(16)]
pub fn check_pop_front_behaviour() {
let data: Vec<u8> = Vec::bounded_any::<16>();
let mut bytes = Bytes::from_source(data.clone());
let snapshot = bytes.clone();

if let Some((expected, remainder)) = data.split_first() {
let popped = bytes.pop_front().expect("non-empty slice");
assert_eq!(popped, *expected);
assert_eq!(bytes.as_ref(), remainder);
} else {
assert!(bytes.pop_front().is_none());
assert_eq!(bytes.as_ref(), snapshot.as_ref());
}
}

#[kani::proof]
#[kani::unwind(16)]
pub fn check_pop_back_behaviour() {
let data: Vec<u8> = Vec::bounded_any::<16>();
let mut bytes = Bytes::from_source(data.clone());
let snapshot = bytes.clone();

if let Some((expected, remainder)) = data.split_last() {
let popped = bytes.pop_back().expect("non-empty slice");
assert_eq!(popped, *expected);
assert_eq!(bytes.as_ref(), remainder);
} else {
assert!(bytes.pop_back().is_none());
assert_eq!(bytes.as_ref(), snapshot.as_ref());
}
}

#[kani::proof]
#[kani::unwind(16)]
pub fn check_slice_to_bytes_ok() {
Expand Down