Use checked_add in VecDeque::append for ZSTs to avoid overflow

(cherry picked from commit 379b18bb0a)
This commit is contained in:
pommicket
2023-02-25 11:05:21 -05:00
committed by Josh Stone
parent 2d33fe73f4
commit 07a8043079
@@ -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;