]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Fix integer underflow in diagnostic
authorPiotr Czarnecki <pioczarn@gmail.com>
Sun, 8 Feb 2015 22:26:12 +0000 (23:26 +0100)
committerPiotr Czarnecki <pioczarn@gmail.com>
Sun, 8 Feb 2015 22:26:12 +0000 (23:26 +0100)
Fixes #22091

src/libsyntax/diagnostic.rs

index 454209bdba2830943791dc2da4d790bbb973fa9c..83a4d938bb5d5567ef9af4fc4fea835aa4e2d2e8 100644 (file)
@@ -518,10 +518,11 @@ fn highlight_lines(err: &mut EmitterWriter,
             let count = match lastc {
                 // Most terminals have a tab stop every eight columns by default
                 '\t' => 8 - col%8,
-                _ => lastc.width(false).unwrap_or(1),
+                _ => lastc.width(false).unwrap_or(0),
             };
             col += count;
-            s.extend(::std::iter::repeat('~').take(count - 1));
+            s.extend(::std::iter::repeat('~').take(count));
+
             let hi = cm.lookup_char_pos(sp.hi);
             if hi.col != lo.col {
                 for (pos, ch) in iter {
@@ -534,6 +535,12 @@ fn highlight_lines(err: &mut EmitterWriter,
                     s.extend(::std::iter::repeat('~').take(count));
                 }
             }
+
+            if s.len() > 1 {
+                // One extra squiggly is replaced by a "^"
+                s.pop();
+            }
+
             try!(print_maybe_styled(err,
                                     &format!("{}\n", s)[],
                                     term::attr::ForegroundColor(lvl.color())));