Fix bounds checking in ArrayVec::insert(index, element)

Must be `index <= len && index < capacity`
This commit is contained in:
bluss
2016-09-21 14:17:57 +02:00
parent d86f06b068
commit 2a1378d3eb
2 changed files with 62 additions and 1 deletions
+5 -1
View File
@@ -179,6 +179,10 @@ impl<A: Array> ArrayVec<A> {
///
/// Return `None` if no element is shifted out.
///
/// `index` must be <= `self.len()` and < `self.capacity()`. Note that any
/// out of bounds index insert results in the element being "shifted out"
/// and returned directly.
///
/// ```
/// use arrayvec::ArrayVec;
///
@@ -192,7 +196,7 @@ impl<A: Array> ArrayVec<A> {
///
/// ```
pub fn insert(&mut self, index: usize, element: A::Item) -> Option<A::Item> {
if index >= self.capacity() {
if index > self.len() || index == self.capacity() {
return Some(element);
}
let mut ret = None;