From df87769988f67045b96c1711eb048f383b78de2a Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 19 Nov 2019 17:42:33 -0500 Subject: [PATCH] Switch to `wrapping_offset` instead of unsafe `offset` --- src/base/storage.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/base/storage.rs b/src/base/storage.rs index 80a6a2d8..e7439552 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -72,16 +72,7 @@ pub unsafe trait Storage: Debug + Sized { /// Gets the address of the i-th matrix component without performing bound-checking. #[inline] unsafe fn get_address_unchecked_linear(&self, i: usize) -> *const N { - let shape = self.shape(); - if shape.0.value() * shape.1.value() == 0 { - // If we have a zero-size matrix, our pointer must - // be dangling. Instead of calling 'offset', we - // just re-use our pointer, since actually using - // it would be undefined behavior - self.ptr() - } else { - self.ptr().offset(i as isize) - } + self.ptr().wrapping_offset(i as isize) } /// Gets the address of the i-th matrix component without performing bound-checking. @@ -133,16 +124,7 @@ pub unsafe trait StorageMut: Storage { /// Gets the mutable address of the i-th matrix component without performing bound-checking. #[inline] unsafe fn get_address_unchecked_linear_mut(&mut self, i: usize) -> *mut N { - let shape = self.shape(); - if shape.0.value() * shape.1.value() == 0 { - // If we have a zero-size matrix, our pointer must - // be dangling. Instead of calling 'offset', we - // just re-use our pointer, since actually using - // it would be undefined behavior - self.ptr_mut() - } else { - self.ptr_mut().offset(i as isize) - } + self.ptr_mut().wrapping_offset(i as isize) } /// Gets the mutable address of the i-th matrix component without performing bound-checking.