Skip to content

Commit 25ae93b

Browse files
committed
count cannot overflow isize in preconditions for byte_add and byte_sub
1 parent dca025f commit 25ae93b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/core/src/ptr/const_ptr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,8 @@ impl<T: ?Sized> *const T {
10601060
// Else if count is not zero, then ensure that adding `count` doesn't cause
10611061
// overflow and that both pointers `self` and the result are in the same
10621062
// allocation
1063-
((self.addr() as isize).checked_add(count as isize).is_some() &&
1063+
(count <= isize::MAX as usize &&
1064+
(self.addr() as isize).checked_add(count as isize).is_some() &&
10641065
core::ub_checks::same_allocation(self, self.wrapping_byte_add(count)))
10651066
)]
10661067
#[ensures(|&result|
@@ -1203,7 +1204,7 @@ impl<T: ?Sized> *const T {
12031204
// Else if count is not zero, then ensure that subtracting `count` doesn't
12041205
// cause overflow and that both pointers `self` and the result are in the
12051206
// same allocation
1206-
((self.addr() as isize).checked_sub(count as isize).is_some() &&
1207+
(count <= isize::MAX as usize && (self.addr() as isize).checked_sub(count as isize).is_some() &&
12071208
core::ub_checks::same_allocation(self, self.wrapping_byte_sub(count)))
12081209
)]
12091210
#[ensures(|&result|

0 commit comments

Comments
 (0)