Skip to content

Commit 12f959b

Browse files
committed
Add test for VecDeque::append ZST capacity overflow
1 parent 379b18b commit 12f959b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/alloc/tests/vec_deque.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,20 @@ fn test_append_double_drop() {
10451045
assert_eq!(count_b, 1);
10461046
}
10471047

1048+
#[test]
1049+
#[should_panic]
1050+
fn test_append_zst_capacity_overflow() {
1051+
let mut v = Vec::with_capacity(usize::MAX);
1052+
// note: using resize instead of set_len here would
1053+
// be *extremely* slow in unoptimized builds.
1054+
// SAFETY: `v` has capacity `usize::MAX`, and no initialization
1055+
// is needed for empty tuples.
1056+
unsafe { v.set_len(usize::MAX) };
1057+
let mut v = VecDeque::from(v);
1058+
let mut w = vec![()].into();
1059+
v.append(&mut w);
1060+
}
1061+
10481062
#[test]
10491063
fn test_retain() {
10501064
let mut buf = VecDeque::new();

0 commit comments

Comments
 (0)