Skip to content

Commit

Permalink
Add test for VecDeque::append ZST capacity overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pommicket committed Feb 25, 2023
1 parent 379b18b commit 12f959b
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 12f959b

Please sign in to comment.