Skip to content

Commit

Permalink
Add bounds check to Vector::insert
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
arcnmx committed Sep 24, 2020
1 parent 76cc185 commit 369e557
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ pub trait Vector {
}

fn insert(&mut self, index: usize, element: Self::Item) {
let len = self.len();
assert!(index <= len);
self.reserve(1);
unsafe {
let len = self.len();
let ptr = self.as_mut_ptr().uoffset(index);
copy(ptr, ptr.uoffset(1), len - index);
write(ptr, element);
Expand Down

0 comments on commit 369e557

Please sign in to comment.