File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1041,7 +1041,7 @@ impl<A: Array> SmallVec<A> {
1041
1041
let mut cur = ptr. add ( num_added) ;
1042
1042
if num_added >= lower_size_bound {
1043
1043
// Iterator provided more elements than the hint. Move trailing items again.
1044
- self . reserve ( 1 ) ;
1044
+ self . reserve ( guard . len + 1 ) ;
1045
1045
let start = self . as_mut_ptr ( ) ;
1046
1046
ptr = start. add ( index) ;
1047
1047
cur = ptr. add ( num_added) ;
Original file line number Diff line number Diff line change @@ -905,3 +905,18 @@ fn empty_macro() {
905
905
fn zero_size_items ( ) {
906
906
SmallVec :: < [ ( ) ; 0 ] > :: new ( ) . push ( ( ) ) ;
907
907
}
908
+
909
+ #[ test]
910
+ fn test_insert_many_overflow ( ) {
911
+ let mut v: SmallVec < [ u8 ; 0 ] > = SmallVec :: new ( ) ;
912
+
913
+ // Spill on heap
914
+ v. push ( 123 ) ;
915
+
916
+ // Prepare an iterator with small lower bound
917
+ let iter = ( 0u8 ..=255 ) . filter ( |n| n % 2 == 0 ) ;
918
+ assert_eq ! ( iter. size_hint( ) . 0 , 0 ) ;
919
+
920
+ // Triggering the bug
921
+ v. insert_many ( 0 , iter) ;
922
+ }
You can’t perform that action at this time.
0 commit comments