Skip to content

Commit

Permalink
Add test for VecDeque::append ZST capacity overflow
Browse files Browse the repository at this point in the history
(cherry picked from commit 12f959b)
  • Loading branch information
pommicket authored and cuviper committed Mar 3, 2023
1 parent 07a8043 commit 005892a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/alloc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,20 @@ fn test_append_double_drop() {
assert_eq!(count_b, 1);
}

#[test]
#[should_panic]
fn test_append_zst_capacity_overflow() {
let mut v = Vec::with_capacity(usize::MAX);
// note: using resize instead of set_len here would
// be *extremely* slow in unoptimized builds.
// SAFETY: `v` has capacity `usize::MAX`, and no initialization
// is needed for empty tuples.
unsafe { v.set_len(usize::MAX) };
let mut v = VecDeque::from(v);
let mut w = vec![()].into();
v.append(&mut w);
}

#[test]
fn test_retain() {
let mut buf = VecDeque::new();
Expand Down

0 comments on commit 005892a

Please sign in to comment.