Skip to content

Commit 7d20bb5

Browse files
committed
iter::slice_skip remove possibility of underflow in debug_assert
`self.cursor.sub(skip)` must point inside the allocation of this object or this is UB, not to mention the possibility that if `skip` if very large self.cursor.sub(skip) may underflow and fail to trigger the debug_assertion.
1 parent 0e1b088 commit 7d20bb5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'a> Bytes<'a> {
109109
/// implies a skip of at most 3).
110110
#[inline]
111111
pub unsafe fn slice_skip(&mut self, skip: usize) -> &'a [u8] {
112-
debug_assert!(self.cursor.sub(skip) >= self.start);
112+
debug_assert!(skip <= self.cursor.offset_from(self.start) as usize);
113113
let head = slice_from_ptr_range(self.start, self.cursor.sub(skip));
114114
self.commit();
115115
head

0 commit comments

Comments
 (0)