Skip to content

Commit

Permalink
address: rename Address::checked_offset() to checked_add()
Browse files Browse the repository at this point in the history
Since we have checked_sub() mirroring the method on int types, be
consistent and rename checked_offset() to checked_add() to match the
int types as well.

Signed-off-by: Carlos López <[email protected]>
  • Loading branch information
00xc committed Oct 24, 2023
1 parent ca05997 commit c19ad83
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait Address:
self.is_aligned(PAGE_SIZE)
}

fn checked_offset(&self, off: InnerAddr) -> Option<Self> {
fn checked_add(&self, off: InnerAddr) -> Option<Self> {
self.bits().checked_add(off).map(|addr| addr.into())
}

Expand Down Expand Up @@ -262,7 +262,7 @@ impl ops::Add<InnerAddr> for VirtAddr {
}

impl Address for VirtAddr {
fn checked_offset(&self, off: InnerAddr) -> Option<Self> {
fn checked_add(&self, off: InnerAddr) -> Option<Self> {
self.bits()
.checked_add(off)
.map(|addr| sign_extend(addr).into())
Expand Down
2 changes: 1 addition & 1 deletion src/debug/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct StackBounds {
#[cfg(feature = "enable-stacktrace")]
impl StackBounds {
fn range_is_on_stack(&self, begin: VirtAddr, len: usize) -> bool {
match begin.checked_offset(len) {
match begin.checked_add(len) {
Some(end) => begin >= self.bottom && end <= self.top,
None => false,
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/memory_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
/// assert!(region.is_none());
/// ```
pub fn checked_new(start: A, len: usize) -> Option<Self> {
let end = start.checked_offset(len)?;
let end = start.checked_add(len)?;
Some(Self { start, end })
}

Expand Down

0 comments on commit c19ad83

Please sign in to comment.