Skip to content

Commit

Permalink
fix integer overflow in error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jan 31, 2024
1 parent 7affd2c commit dc033ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl Report {
let color: String = line
.chars()
.skip(start_char_pos as usize)
.take((end_char_pos - start_char_pos) as usize)
.take(end_char_pos.saturating_sub(start_char_pos).max(1) as usize)
.collect();
let post_color: String = line.chars().skip(end_char_pos as usize).collect();
fragments.push(ReportFragment::Faint(pre_color));
Expand All @@ -418,7 +418,7 @@ impl Report {
));
fragments.push(ReportFragment::Plain(" ".repeat(start_char_pos as usize)));
fragments.push(ReportFragment::Colored(
"─".repeat((end_char_pos - start_char_pos) as usize),
"─".repeat(end_char_pos.saturating_sub(start_char_pos).max(1) as usize),
));
}
}
Expand Down

0 comments on commit dc033ed

Please sign in to comment.