Skip to content

Commit 9a902b1

Browse files
committed
Try swapping wrapping_add and wrapping_sub
1 parent 35f28d8 commit 9a902b1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<T: ?Sized> *const T {
260260
//
261261
// As a result, we use the following implementation, which would be
262262
// wrong on CHERI, but right everywhere else.
263-
self.cast::<u8>().wrapping_sub(self_addr).wrapping_add(addr).cast::<T>()
263+
self.cast::<u8>().wrapping_add(addr).wrapping_sub(self_addr).cast::<T>()
264264
}
265265

266266
/// Creates a new pointer by mapping `self`'s address to a new one.

library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<T: ?Sized> *mut T {
264264
//
265265
// As a result, we use the following implementation, which would be
266266
// wrong on CHERI, but right everywhere else.
267-
self.cast::<u8>().wrapping_sub(self_addr).wrapping_add(addr).cast::<T>()
267+
self.cast::<u8>().wrapping_add(addr).wrapping_sub(self_addr).cast::<T>()
268268
}
269269

270270
/// Creates a new pointer by mapping `self`'s address to a new one.

0 commit comments

Comments
 (0)