diff options
| author | pommicket <pommicket@gmail.com> | 2023-02-25 13:50:56 -0500 |
|---|---|---|
| committer | pommicket <pommicket@gmail.com> | 2023-02-25 13:50:56 -0500 |
| commit | 12f959ba39ad353ce07971aaf8cef564f86b068d (patch) | |
| tree | bdfd6fb74efbeb71abb27daac26a4b0999e9ebf2 | |
| parent | 379b18bb0ab07e8f7ba04ca29ba52a1817cec1ce (diff) | |
| download | rust-12f959ba39ad353ce07971aaf8cef564f86b068d.tar.gz rust-12f959ba39ad353ce07971aaf8cef564f86b068d.zip | |
Add test for VecDeque::append ZST capacity overflow
| -rw-r--r-- | library/alloc/tests/vec_deque.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/library/alloc/tests/vec_deque.rs b/library/alloc/tests/vec_deque.rs index 0b8f5281b78..5a0b852e8d5 100644 --- a/library/alloc/tests/vec_deque.rs +++ b/library/alloc/tests/vec_deque.rs @@ -1046,6 +1046,20 @@ fn test_append_double_drop() { } #[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(); buf.extend(1..5); |
