Skip to content

Commit

Permalink
Auto merge of rust-lang#26563 - sfackler:vec-from-iter-overflow, r=Ga…
Browse files Browse the repository at this point in the history
…nkro

Closes rust-lang#26550
  • Loading branch information
bors committed Jun 25, 2015
2 parents 23958d8 + 18e78b9 commit 124d165
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ impl<T> FromIterator<T> for Vec<T> {
None => return Vec::new(),
Some(element) => {
let (lower, _) = iterator.size_hint();
let mut vector = Vec::with_capacity(1 + lower);
let mut vector = Vec::with_capacity(lower.saturating_add(1));
unsafe {
ptr::write(vector.get_unchecked_mut(0), element);
vector.set_len(1);
Expand Down Expand Up @@ -1570,10 +1570,11 @@ impl<T> Vec<T> {
let len = self.len();
if len == self.capacity() {
let (lower, _) = iterator.size_hint();
self.reserve(lower + 1);
self.reserve(lower.saturating_add(1));
}
unsafe {
ptr::write(self.get_unchecked_mut(len), element);
// NB can't overflow since we would have had to alloc the address space
self.set_len(len + 1);
}
}
Expand Down

0 comments on commit 124d165

Please sign in to comment.