Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-Simulacrum
Detect overflow in proc_macro_server subspan * Detect overflow in proc_macro_server subspan * Add tests for overflow in Vec::drain * Add tests for overflow in String / VecDeque operations using ranges
This commit is contained in:
commit
fb9bb2b5ca
5 changed files with 72 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::TryReserveError::*;
|
||||
use std::mem::size_of;
|
||||
use std::ops::Bound::*;
|
||||
|
||||
pub trait IntoCow<'a, B: ?Sized>
|
||||
where
|
||||
|
@ -467,6 +468,20 @@ fn test_drain() {
|
|||
assert_eq!(t, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_drain_start_overflow() {
|
||||
let mut s = String::from("abc");
|
||||
s.drain((Excluded(usize::MAX), Included(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_drain_end_overflow() {
|
||||
let mut s = String::from("abc");
|
||||
s.drain((Included(0), Included(usize::MAX)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_range() {
|
||||
let mut s = "Hello, world!".to_owned();
|
||||
|
@ -504,6 +519,20 @@ fn test_replace_range_inclusive_out_of_bounds() {
|
|||
s.replace_range(5..=5, "789");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_replace_range_start_overflow() {
|
||||
let mut s = String::from("123");
|
||||
s.replace_range((Excluded(usize::MAX), Included(0)), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_replace_range_end_overflow() {
|
||||
let mut s = String::from("456");
|
||||
s.replace_range((Included(0), Included(usize::MAX)), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_range_empty() {
|
||||
let mut s = String::from("12345");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue