diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-08-04 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-09-04 23:16:53 +0200 |
| commit | d98bac4e4e3cc87ec9b848c173d570ebe2aa30b6 (patch) | |
| tree | fe5a0c91c107c0d3bd9b4e0e617a770b50466de5 /library/alloc | |
| parent | b54386ab7a9da8a4f22db3a35a9ec7b0f2b98b6c (diff) | |
| download | rust-d98bac4e4e3cc87ec9b848c173d570ebe2aa30b6.tar.gz rust-d98bac4e4e3cc87ec9b848c173d570ebe2aa30b6.zip | |
Add tests for overflow in Vec::drain
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/tests/vec.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 8e66c8a22ce..8abebd940d2 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -3,6 +3,7 @@ use std::collections::TryReserveError::*; use std::fmt::Debug; use std::iter::InPlaceIterable; use std::mem::size_of; +use std::ops::Bound::*; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::rc::Rc; use std::vec::{Drain, IntoIter}; @@ -568,12 +569,36 @@ fn test_drain_max_vec_size() { #[test] #[should_panic] +fn test_drain_index_overflow() { + let mut v = Vec::<()>::with_capacity(usize::MAX); + unsafe { + v.set_len(usize::MAX); + } + v.drain(0..=usize::MAX); +} + +#[test] +#[should_panic] fn test_drain_inclusive_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; v.drain(5..=5); } #[test] +#[should_panic] +fn test_drain_start_overflow() { + let mut v = vec![1, 2, 3]; + v.drain((Excluded(usize::MAX), Included(0))); +} + +#[test] +#[should_panic] +fn test_drain_end_overflow() { + let mut v = vec![1, 2, 3]; + v.drain((Included(0), Included(usize::MAX))); +} + +#[test] fn test_drain_leak() { static mut DROPS: i32 = 0; |
