Switch to `wrapping_offset` instead of unsafe `offset`
This commit is contained in:
parent
4e25bd87fb
commit
e981283500
|
@ -72,16 +72,7 @@ pub unsafe trait Storage<N: Scalar, R: Dim, C: Dim = U1>: 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<N: Scalar, R: Dim, C: Dim = U1>: Storage<N, R, C> {
|
|||
/// 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.
|
||||
|
|
Loading…
Reference in New Issue