File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -990,11 +990,13 @@ impl BufMut for Vec<u8> {
990
990
unsafe fn advance_mut ( & mut self , cnt : usize ) {
991
991
let len = self . len ( ) ;
992
992
let remaining = self . capacity ( ) - len;
993
- if cnt > remaining {
994
- // Reserve additional capacity, and ensure that the total length
995
- // will not overflow usize.
996
- self . reserve ( cnt) ;
997
- }
993
+
994
+ assert ! (
995
+ cnt <= remaining,
996
+ "cannot advance past `remaining_mut`: {:?} <= {:?}" ,
997
+ cnt,
998
+ remaining
999
+ ) ;
998
1000
999
1001
self . set_len ( len + cnt) ;
1000
1002
}
Original file line number Diff line number Diff line change @@ -45,13 +45,12 @@ fn test_put_u16() {
45
45
}
46
46
47
47
#[ test]
48
+ #[ should_panic( expected = "cannot advance" ) ]
48
49
fn test_vec_advance_mut ( ) {
49
- // Regression test for carllerche/bytes#108.
50
+ // Verify fix for #354
50
51
let mut buf = Vec :: with_capacity ( 8 ) ;
51
52
unsafe {
52
53
buf. advance_mut ( 12 ) ;
53
- assert_eq ! ( buf. len( ) , 12 ) ;
54
- assert ! ( buf. capacity( ) >= 12 , "capacity: {}" , buf. capacity( ) ) ;
55
54
}
56
55
}
57
56
You can’t perform that action at this time.
0 commit comments