mirror of
https://github.com/openharmony/third_party_rust_rust-smallvec.git
synced 2026-07-19 23:03:32 -04:00
Auto merge of #259 - mbrubeck:overflow, r=emilio
Panic on arithmetic overflow in drain Fixes #258.
This commit is contained in:
+2
-2
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user