Skip to content

Commit 89b2e9f

Browse files
committed
syntax: Fix integer underflow in diagnostic
Fixes #22091
1 parent d4f9ec5 commit 89b2e9f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,11 @@ fn highlight_lines(err: &mut EmitterWriter,
518518
let count = match lastc {
519519
// Most terminals have a tab stop every eight columns by default
520520
'\t' => 8 - col%8,
521-
_ => lastc.width(false).unwrap_or(1),
521+
_ => lastc.width(false).unwrap_or(0),
522522
};
523523
col += count;
524-
s.extend(::std::iter::repeat('~').take(count - 1));
524+
s.extend(::std::iter::repeat('~').take(count));
525+
525526
let hi = cm.lookup_char_pos(sp.hi);
526527
if hi.col != lo.col {
527528
for (pos, ch) in iter {
@@ -534,6 +535,12 @@ fn highlight_lines(err: &mut EmitterWriter,
534535
s.extend(::std::iter::repeat('~').take(count));
535536
}
536537
}
538+
539+
if s.len() > 1 {
540+
// One extra squiggly is replaced by a "^"
541+
s.pop();
542+
}
543+
537544
try!(print_maybe_styled(err,
538545
&format!("{}\n", s)[],
539546
term::attr::ForegroundColor(lvl.color())));

0 commit comments

Comments
 (0)