File tree 2 files changed +12
-2
lines changed
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -249,9 +249,10 @@ impl<'a> BorrowedCursor<'a> {
249
249
/// Panics if there are less than `n` bytes initialized.
250
250
#[ inline]
251
251
pub fn advance ( & mut self , n : usize ) -> & mut Self {
252
- assert ! ( self . buf. init >= self . buf. filled + n) ;
252
+ let filled = self . buf . filled . strict_add ( n) ;
253
+ assert ! ( filled <= self . buf. init) ;
253
254
254
- self . buf . filled += n ;
255
+ self . buf . filled = filled ;
255
256
self
256
257
}
257
258
Original file line number Diff line number Diff line change @@ -209,6 +209,15 @@ fn read_buf_exact() {
209
209
assert_eq ! ( c. read_buf_exact( buf. unfilled( ) ) . unwrap_err( ) . kind( ) , io:: ErrorKind :: UnexpectedEof ) ;
210
210
}
211
211
212
+ #[ test]
213
+ #[ should_panic]
214
+ fn borrowed_cursor_advance_overflow ( ) {
215
+ let mut buf = [ 0 ; 512 ] ;
216
+ let mut buf = BorrowedBuf :: from ( & mut buf[ ..] ) ;
217
+ buf. unfilled ( ) . advance ( 1 ) ;
218
+ buf. unfilled ( ) . advance ( usize:: MAX ) ;
219
+ }
220
+
212
221
#[ test]
213
222
fn take_eof ( ) {
214
223
struct R ;
You can’t perform that action at this time.
0 commit comments