File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 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> {
249249 /// Panics if there are less than `n` bytes initialized.
250250 #[ inline]
251251 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) ;
253254
254- self . buf . filled += n ;
255+ self . buf . filled = filled ;
255256 self
256257 }
257258
Original file line number Diff line number Diff line change @@ -209,6 +209,15 @@ fn read_buf_exact() {
209209 assert_eq ! ( c. read_buf_exact( buf. unfilled( ) ) . unwrap_err( ) . kind( ) , io:: ErrorKind :: UnexpectedEof ) ;
210210}
211211
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+
212221#[ test]
213222fn take_eof ( ) {
214223 struct R ;
You can’t perform that action at this time.
0 commit comments