Skip to content

Commit

Permalink
fix: Bitfield::with_capacity OutOfBounds field bug
Browse files Browse the repository at this point in the history
It was returning the max length twice, and now returns the actual length
and maximum length.
  • Loading branch information
carver committed Sep 25, 2024
1 parent 6371448 commit 90ed130
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ssz/src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<N: Unsigned + Clone> Bitfield<Variable<N>> {
})
} 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 @@ mod bitlist {
// 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 });
}
}

0 comments on commit 90ed130

Please sign in to comment.