Skip to content

Commit 6ac4f73

Browse files
authored
SFTSpaceMap should do range check in get_checked (#1339)
Like other `SFTMap` implementations, `SFTSpaceMap.get_checked` should also check `has_sft_entry` before calling `self.get_unchecked`. Fixes: #1338
1 parent 7fe0e05 commit 6ac4f73

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/policy/sft_map.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,13 @@ mod space_map {
182182
}
183183

184184
fn get_checked(&self, address: Address) -> &dyn SFT {
185-
// We should be able to map the entire address range to indices in the table.
186-
debug_assert!(Self::addr_to_index(address) < self.sft.len());
187-
unsafe { self.get_unchecked(address) }
185+
if self.has_sft_entry(address) {
186+
// We should be able to map the entire address range to indices in the table.
187+
debug_assert!(Self::addr_to_index(address) < self.sft.len());
188+
unsafe { self.get_unchecked(address) }
189+
} else {
190+
&EMPTY_SPACE_SFT
191+
}
188192
}
189193

190194
unsafe fn get_unchecked(&self, address: Address) -> &dyn SFT {

0 commit comments

Comments
 (0)