Skip to content

Commit 07a8043

Browse files
pommicketcuviper
authored andcommitted
Use checked_add in VecDeque::append for ZSTs to avoid overflow
(cherry picked from commit 379b18b)
1 parent 2d33fe7 commit 07a8043

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
@@ -1924,7 +1924,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
19241924
#[stable(feature = "append", since = "1.4.0")]
19251925
pub fn append(&mut self, other: &mut Self) {
19261926
if T::IS_ZST {
1927-
self.len += other.len;
1927+
self.len = self.len.checked_add(other.len).expect("capacity overflow");
19281928
other.len = 0;
19291929
other.head = 0;
19301930
return;

0 commit comments

Comments
 (0)