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

This commit is contained in:
pommicket 2023-02-25 11:05:21 -05:00
parent 26c98689f2
commit 379b18bb0a
1 changed files with 1 additions and 1 deletions

View File

@ -1917,7 +1917,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
#[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;