Skip to content

fix: check vaild frist when relative_pos_range close #94 #95

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
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
9 changes: 6 additions & 3 deletions rapx/src/utils/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ pub fn span_to_line_number(span: Span) -> usize {
#[inline]
// this function computes the relative pos range of two spans which could be generated from two dirrerent files or not intersect with each other
pub unsafe fn relative_pos_range(span: Span, sub_span: Span) -> Range<usize> {
let start_pos = span.lo();
let lo = (sub_span.lo() - start_pos).to_usize(); //unsafe: overflow
let hi = (sub_span.hi() - start_pos).to_usize();
if sub_span.lo() < span.lo() || sub_span.hi() > span.hi() {
return 0..0;
}
let offset = span.lo();
let lo = (sub_span.lo() - offset).to_usize();
let hi = (sub_span.hi() - offset).to_usize();
lo..hi
}

Expand Down