Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(debugger): a potential underflow in memory highlighting #6508

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions crates/debugger/src/tui/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,13 @@ Line::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/k
-2 => Some(1),
-1 => Some(32),
0 => None,
1.. => Some(stack[stack_len - stack_index as usize].saturating_to()),
1.. => {
if (stack_index as usize) <= stack_len {
Some(stack[stack_len - stack_index as usize].saturating_to())
} else {
None
}
}
_ => panic!("invalid stack index"),
};

Expand Down Expand Up @@ -862,11 +868,7 @@ Line::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/k
Span::styled(
format!("{byte:02x} "),
if let (Some(offset), Some(size), Some(color)) = (offset, size, color) {
if (i == offset / 32 && j >= offset % 32) ||
(i > offset / 32 && i < (offset + size - 1) / 32) ||
(i == (offset + size - 1) / 32 &&
j <= (offset + size - 1) % 32)
{
if i * 32 + j >= offset && i * 32 + j < offset + size {
// [offset, offset + size] is the memory region to be colored.
// If a byte at row i and column j in the memory panel
// falls in this region, set the color.
Expand Down
Loading