Skip to content

Commit ecf05d5

Browse files
committed
Avoid overflow in BorrowedCursor::advance
1 parent 6aa14d8 commit ecf05d5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/core/src/io/borrowed_buf.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@ impl<'a> BorrowedCursor<'a> {
261261
/// Panics if there are less than `n` bytes initialized.
262262
#[inline]
263263
pub fn advance(&mut self, n: usize) -> &mut Self {
264-
assert!(self.buf.init >= self.buf.filled + n);
264+
let new_filled = self.buf.filled.strict_add(n);
265+
assert!(self.buf.init >= new_filled);
265266

266-
self.buf.filled += n;
267+
self.buf.filled = new_filled;
267268
self
268269
}
269270

0 commit comments

Comments
 (0)