From 07a804307991dc96613fbf208e91f0ae3cdf318b Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 25 Feb 2023 11:05:21 -0500 Subject: [PATCH] Use checked_add in VecDeque::append for ZSTs to avoid overflow (cherry picked from commit 379b18bb0ab07e8f7ba04ca29ba52a1817cec1ce) --- library/alloc/src/collections/vec_deque/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index d4a12509b1cf..8317ac431a5e 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1924,7 +1924,7 @@ pub fn split_off(&mut self, at: usize) -> Self #[stable(feature = "append", since = "1.4.0")] pub fn append(&mut self, other: &mut Self) { if T::IS_ZST { - self.len += other.len; + self.len = self.len.checked_add(other.len).expect("capacity overflow"); other.len = 0; other.head = 0; return;