Skip to content

Commit

Permalink
fix overflow/underflow checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Freax13 committed Mar 1, 2022
1 parent 2909487 commit 9bef8f0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,16 @@ impl Step for VirtAddr {

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

// Jump the gap by sign extending the 47th bit.
if addr.get_bits(47..) == 0x1 {
addr.set_bits(47.., 0x1ffff);
match addr.get_bits(47..) {
0x1 => {
// Jump the gap by sign extending the 47th bit.
addr.set_bits(47.., 0x1ffff);
}
0x2 => {
// Address overflow
return None;
}
_ => {}
}

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

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

// Jump the gap by sign extending the 47th bit.
if addr.get_bits(47..) == 0x1fffe {
addr.set_bits(47.., 0);
match addr.get_bits(47..) {
0x1fffe => {
// Jump the gap by sign extending the 47th bit.
addr.set_bits(47.., 0);
}
0x1fffd => {
// Address underflow
return None;
}
_ => {}
}

Some(Self::new(addr))
Expand Down

0 comments on commit 9bef8f0

Please sign in to comment.