Skip to content

Commit 9bef8f0

Browse files
committed
fix overflow/underflow checks
1 parent 2909487 commit 9bef8f0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/addr.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,16 @@ impl Step for VirtAddr {
349349

350350
let mut addr = start.0.checked_add(offset)?;
351351

352-
// Jump the gap by sign extending the 47th bit.
353-
if addr.get_bits(47..) == 0x1 {
354-
addr.set_bits(47.., 0x1ffff);
352+
match addr.get_bits(47..) {
353+
0x1 => {
354+
// Jump the gap by sign extending the 47th bit.
355+
addr.set_bits(47.., 0x1ffff);
356+
}
357+
0x2 => {
358+
// Address overflow
359+
return None;
360+
}
361+
_ => {}
355362
}
356363

357364
Some(Self::new(addr))
@@ -365,9 +372,16 @@ impl Step for VirtAddr {
365372

366373
let mut addr = start.0.checked_sub(offset)?;
367374

368-
// Jump the gap by sign extending the 47th bit.
369-
if addr.get_bits(47..) == 0x1fffe {
370-
addr.set_bits(47.., 0);
375+
match addr.get_bits(47..) {
376+
0x1fffe => {
377+
// Jump the gap by sign extending the 47th bit.
378+
addr.set_bits(47.., 0);
379+
}
380+
0x1fffd => {
381+
// Address underflow
382+
return None;
383+
}
384+
_ => {}
371385
}
372386

373387
Some(Self::new(addr))

0 commit comments

Comments
 (0)