What changed, and why it matters
This is a small internal code cleanup in the rust-bitcoin library. A function called `push` that adds items to a fixed-size array was rewritten to call a newer helper function (`try_push`) instead of doing the work directly. The behavior is unchanged: it still panics if the array is full, just with a slightly different panic message. There is no security issue here.
No action needed. This is a benign refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors ArrayVec::push in internals/src/array_vec.rs to delegate to try_push, unwrapping the result with expect. Previously, push used an explicit assert!, wrote the element into MaybeUninit storage, and incremented len. After the change, the same capacity check and write happen inside try_push, and expect panics with the message “push past the capacity of the array” on failure. The test’s expected panic string was updated accordingly. This is a pure refactoring with no functional or safety change.
Changed components
internals/src/array_vec.rsInspect captured patch +2 / −4
diff --git a/internals/src/array_vec.rs b/internals/src/array_vec.rs
index 4be956ce..8aa90d73 100644
--- a/internals/src/array_vec.rs
+++ b/internals/src/array_vec.rs
@@ -67,9 +67,7 @@ mod safety_boundary {
///
/// If the length would increase past CAP.
pub fn push(&mut self, element: T) {
- assert!(self.len < CAP);
- self.data[self.len] = MaybeUninit::new(element);
- self.len += 1;
+ self.try_push(element).expect("push past the capacity of the array");
}
/// Adds an element into `self`.
@@ -297,7 +295,7 @@ mod tests {
}
#[test]
- #[should_panic(expected = "assertion failed")]
+ #[should_panic(expected = "push past the capacity of the array")]
fn overflow_push() {
let mut av = ArrayVec::<_, 0>::new();
av.push(42);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.