Auto merge of #259 - mbrubeck:overflow, r=emilio

Panic on arithmetic overflow in drain

Fixes #258.
This commit is contained in:
bors-servo
2021-03-23 12:32:32 -04:00
committed by GitHub
2 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -725,11 +725,11 @@ impl<A: Array> SmallVec<A> {
let len = self.len();
let start = match range.start_bound() {
Included(&n) => n,
Excluded(&n) => n + 1,
Excluded(&n) => n.checked_add(1).expect("Range start out of bounds"),
Unbounded => 0,
};
let end = match range.end_bound() {
Included(&n) => n + 1,
Included(&n) => n.checked_add(1).expect("Range end out of bounds"),
Excluded(&n) => n,
Unbounded => len,
};
+7
View File
@@ -423,6 +423,13 @@ fn test_invalid_grow() {
v.grow(5);
}
#[test]
#[should_panic]
fn drain_overflow() {
let mut v: SmallVec<[u8; 8]> = smallvec![0];
v.drain(..=std::usize::MAX);
}
#[test]
fn test_insert_from_slice() {
let mut v: SmallVec<[u8; 8]> = SmallVec::new();