Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions hl/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ pub enum SeekFrom {
Current(i16),
}

// TODO: use wrapping_add_signed when stabilized
// https://github.com/rust-lang/rust/issues/87840
// https://github.com/rust-lang/rust/blob/21b0325c68421b00c6c91055ac330bd5ffe1ea6b/library/core/src/num/uint_macros.rs#L1205
fn wrapping_add_signed(ptr: u16, offset: i16) -> u16 {
ptr.wrapping_add(offset as u16)
}

impl SeekFrom {
/// Calculate the next value of `ptr` for the given seek method.
#[doc(hidden)]
Expand All @@ -41,7 +34,7 @@ impl SeekFrom {
if offset > 0 || offset.unsigned_abs() > tail.wrapping_sub(head) {
Err(Error::UnexpectedEof)
} else {
Ok(wrapping_add_signed(tail, offset))
Ok(tail.wrapping_add_signed(offset))
}
}
SeekFrom::Current(offset) => {
Expand All @@ -52,7 +45,7 @@ impl SeekFrom {
{
Err(Error::UnexpectedEof)
} else {
Ok(wrapping_add_signed(ptr, offset))
Ok(ptr.wrapping_add_signed(offset))
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions tls/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,6 @@ pub struct TlsReader<'buf, 'ptr> {
wrap: usize,
}

// TODO: use wrapping_add_signed when stabilized
// https://github.com/rust-lang/rust/issues/87840
// https://github.com/rust-lang/rust/blob/21b0325c68421b00c6c91055ac330bd5ffe1ea6b/library/core/src/num/uint_macros.rs#L1205
fn wrapping_add_signed(ptr: u16, offset: i16) -> u16 {
ptr.wrapping_add(offset as u16)
}

impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> {
fn seek<Infallible>(&mut self, pos: SeekFrom) -> Result<(), HlError<Infallible>> {
match pos {
Expand Down Expand Up @@ -356,7 +349,7 @@ impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> {
if offset < min_val || offset > max_val {
Err(HlError::UnexpectedEof)
} else {
self.inner.ptr = wrapping_add_signed(self.inner.ptr, offset);
self.inner.ptr = self.inner.ptr.wrapping_add_signed(offset);
Ok(())
}
}
Expand Down