Skip to content

Commit 65f72d1

Browse files
author
bors-servo
authored
Auto merge of #122 - llogiq:from-slice-cap, r=mbrubeck
fix from_slice possible overallocation @arthurps found that the code would underreport the vec's capacity if `slice.to_vec()` allocated more than `len` entries. This changes the code to set the correct capacity as reported from the `vec`. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/122) <!-- Reviewable:end -->
2 parents 04e3c4e + 3400726 commit 65f72d1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,10 @@ impl<A: Array> SmallVec<A> where A::Item: Copy {
958958
}
959959
} else {
960960
let mut b = slice.to_vec();
961-
let ptr = b.as_mut_ptr();
961+
let (ptr, cap) = (b.as_mut_ptr(), b.capacity());
962962
mem::forget(b);
963963
SmallVec {
964-
capacity: len,
964+
capacity: cap,
965965
data: SmallVecData::from_heap(ptr, len),
966966
}
967967
}

0 commit comments

Comments
 (0)