Skip to content

Commit 8b27976

Browse files
authored
Merge pull request #5 from Spxg/main
VirtAddr: fix add with overflow when debug mode
2 parents 00084f5 + 84a55c1 commit 8b27976

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

os/src/mm/address.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl From<VirtPageNum> for usize {
7373

7474
impl VirtAddr {
7575
pub fn floor(&self) -> VirtPageNum { VirtPageNum(self.0 / PAGE_SIZE) }
76-
pub fn ceil(&self) -> VirtPageNum { VirtPageNum((self.0 + PAGE_SIZE - 1) / PAGE_SIZE) }
76+
pub fn ceil(&self) -> VirtPageNum { VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) }
7777
pub fn page_offset(&self) -> usize { self.0 & (PAGE_SIZE - 1) }
7878
pub fn aligned(&self) -> bool { self.page_offset() == 0 }
7979
}
@@ -88,7 +88,7 @@ impl From<VirtPageNum> for VirtAddr {
8888
}
8989
impl PhysAddr {
9090
pub fn floor(&self) -> PhysPageNum { PhysPageNum(self.0 / PAGE_SIZE) }
91-
pub fn ceil(&self) -> PhysPageNum { PhysPageNum((self.0 + PAGE_SIZE - 1) / PAGE_SIZE) }
91+
pub fn ceil(&self) -> PhysPageNum { PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) }
9292
pub fn page_offset(&self) -> usize { self.0 & (PAGE_SIZE - 1) }
9393
pub fn aligned(&self) -> bool { self.page_offset() == 0 }
9494
}

0 commit comments

Comments
 (0)