Skip to content

Commit 379b18b

Browse files
committed
Use checked_add in VecDeque::append for ZSTs to avoid overflow
1 parent 26c9868 commit 379b18b

File tree

1 file changed

+1
-1
lines changed
  • library/alloc/src/collections/vec_deque

1 file changed

+1
-1
lines changed

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
19171917
#[stable(feature = "append", since = "1.4.0")]
19181918
pub fn append(&mut self, other: &mut Self) {
19191919
if T::IS_ZST {
1920-
self.len += other.len;
1920+
self.len = self.len.checked_add(other.len).expect("capacity overflow");
19211921
other.len = 0;
19221922
other.head = 0;
19231923
return;

0 commit comments

Comments
 (0)