Skip to content

coverage: Don't underflow column number #97368

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

Merged
merged 1 commit into from
Apr 26, 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
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
@@ -515,7 +515,7 @@ fn make_code_region(
// Extend an empty span by one character so the region will be counted.
let CharPos(char_pos) = start_col;
if span.hi() == body_span.hi() {
start_col = CharPos(char_pos - 1);
start_col = CharPos(char_pos.saturating_sub(1));
Copy link
Member

@wesleywiser wesleywiser May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should fix the rest of this function to use saturating math since it's not much code? Specifically, can we also fix the addition on lines 520, 531 and 533?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmandry - Do you mind doing that, if you agree it's worth it?

Sorry for the bug, but I thought lookup_file_pos() should never return less than 1. Maybe I misunderstood or the implementation changed, but that's not something the compiler would have enforced of course, so this is a good fix. Thanks.

} else {
end_col = CharPos(char_pos + 1);
}