diff --git a/hl/src/io.rs b/hl/src/io.rs index 0b4a6b40..9f243959 100644 --- a/hl/src/io.rs +++ b/hl/src/io.rs @@ -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)] @@ -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) => { @@ -52,7 +45,7 @@ impl SeekFrom { { Err(Error::UnexpectedEof) } else { - Ok(wrapping_add_signed(ptr, offset)) + Ok(ptr.wrapping_add_signed(offset)) } } } diff --git a/tls/src/io.rs b/tls/src/io.rs index 57a04526..fbf9bb43 100644 --- a/tls/src/io.rs +++ b/tls/src/io.rs @@ -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(&mut self, pos: SeekFrom) -> Result<(), HlError> { match pos { @@ -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(()) } }