Skip to content

Commit

Permalink
Proposed fix for rustsec/advisory-db#847
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Apr 12, 2021
1 parent d0382d5 commit f45657d
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,27 +894,10 @@ impl<A: Array> iter::FromIterator<A::Item> for StackVec<A> {

impl<A: Array> Extend<A::Item> for StackVec<A> {
fn extend<I: iter::IntoIterator<Item=A::Item>>(&mut self, iterable: I) {
let mut iter = iterable.into_iter();
let (lower_bound, upper_bound) = iter.size_hint();
let upper_bound = upper_bound.expect("iterable must provide upper bound.");
assert!(self.len() + upper_bound <= self.capacity());

unsafe {
let len = self.len();
let ptr = self.as_mut_ptr().padd(len);
let mut count = 0;
while count < lower_bound {
if let Some(out) = iter.next() {
ptr::write(ptr.padd(count), out);
count += 1;
} else {
break;
}
}
self.set_len(len + count);
}

for elem in iter {
// size_hint() has no safety guarantees, and TrustedLen
// is nightly only, so we can't do any optimizations with
// size_hint.
for elem in iterable.into_iter() {
self.push(elem);
}
}
Expand Down

0 comments on commit f45657d

Please sign in to comment.