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

Bitfield::with_capacity fix OutOfBounds i field, plus doc typo fix #33

Merged
merged 2 commits into from
Sep 26, 2024
Merged
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
10 changes: 8 additions & 2 deletions ssz/src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
///
/// All bits are initialized to `false`.
///
/// Returns `None` if `num_bits > N`.
/// Returns `Err` if `num_bits > N`.
pub fn with_capacity(num_bits: usize) -> Result<Self, Error> {
if num_bits <= N::to_usize() {
Ok(Self {
Expand All @@ -135,7 +135,7 @@
})
} else {
Err(Error::OutOfBounds {
i: Self::max_len(),
i: num_bits,

Check warning on line 138 in ssz/src/bitfield.rs

View check run for this annotation

Codecov / codecov/patch

ssz/src/bitfield.rs#L138

Added line #L138 was not covered by tests
len: Self::max_len(),
})
}
Expand Down Expand Up @@ -1429,4 +1429,10 @@
// Can't extend a BitList to a smaller BitList
resized_bit_list.resize::<typenum::U16>().unwrap_err();
}

#[test]
fn over_capacity_err() {
let e = BitList8::with_capacity(9).expect_err("over-sized bit list");
assert_eq!(e, Error::OutOfBounds { i: 9, len: 8 });
}
}
Loading