Skip to content

Commit 96cf444

Browse files
author
Nate Catelli
committed
use checked_* methods
1 parent 19a5fe3 commit 96cf444

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/structures/paging/frame.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ impl<S: PageSize> core::iter::Step for PhysFrame<S> {
146146
use core::convert::TryFrom;
147147

148148
match u64::try_from(count) {
149-
Ok(n) => match start.start_address().as_u64().overflowing_add(n * S::SIZE) {
150-
(_, true) => None,
151-
(start_addr, false) => Self::from_start_address(PhysAddr::new(start_addr)).ok(),
152-
},
149+
Ok(n) => start
150+
.start_address()
151+
.as_u64()
152+
.checked_add(n * S::SIZE)
153+
.and_then(|start_addr| Self::from_start_address(PhysAddr::new(start_addr)).ok()),
153154
Err(_) => None, // if n is out of range, `unsigned_start + n`
154155
}
155156
}
@@ -158,10 +159,11 @@ impl<S: PageSize> core::iter::Step for PhysFrame<S> {
158159
use core::convert::TryFrom;
159160

160161
match u64::try_from(count) {
161-
Ok(n) => match start.start_address().as_u64().overflowing_sub(n * S::SIZE) {
162-
(_, true) => None,
163-
(start_addr, false) => Self::from_start_address(PhysAddr::new(start_addr)).ok(),
164-
},
162+
Ok(n) => start
163+
.start_address()
164+
.as_u64()
165+
.checked_sub(n * S::SIZE)
166+
.and_then(|start_addr| Self::from_start_address(PhysAddr::new(start_addr)).ok()),
165167
Err(_) => None, // if n is out of range, `unsigned_start + n`
166168
}
167169
}

0 commit comments

Comments
 (0)