From 90ed13086b74feecaaa24e36032647edba374f14 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 24 Sep 2024 21:06:20 -0700 Subject: [PATCH] fix: Bitfield::with_capacity OutOfBounds field bug It was returning the max length twice, and now returns the actual length and maximum length. --- ssz/src/bitfield.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ssz/src/bitfield.rs b/ssz/src/bitfield.rs index ff34299..15c9eba 100644 --- a/ssz/src/bitfield.rs +++ b/ssz/src/bitfield.rs @@ -135,7 +135,7 @@ impl Bitfield> { }) } else { Err(Error::OutOfBounds { - i: Self::max_len(), + i: num_bits, len: Self::max_len(), }) } @@ -1429,4 +1429,10 @@ mod bitlist { // Can't extend a BitList to a smaller BitList resized_bit_list.resize::().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 }); + } }