]> granicus.if.org Git - clang/commitdiff
Fix crash in source-line truncation code for diagnostic
authorDouglas Gregor <dgregor@apple.com>
Sun, 3 May 2009 15:24:25 +0000 (15:24 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 3 May 2009 15:24:25 +0000 (15:24 +0000)
printing. Also, when we only need to truncate the line at the end,
make sure there is room for the ellipsis.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70781 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnosticPrinter.cpp

index 042e894febcfb63feec76a0552b0639d28c40254..62446f33007945dd88333a0bda852829efaa0b67 100644 (file)
@@ -158,7 +158,7 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
 
   // If the end of the interesting region comes before we run out of
   // space in the terminal, start at the beginning of the line.
-  if (CaretEnd < Columns)
+  if (CaretEnd < Columns - 3)
     CaretStart = 0;
 
   unsigned TargetColumns = Columns - 8; // Give us extra room for the ellipses.
@@ -251,7 +251,8 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
   // before the lines so that it looks nicer.
   if (CaretEnd < SourceLine.size())
     SourceLine.replace(CaretEnd, std::string::npos, "...");
-  //CaretLine.erase(CaretEnd, std::string::npos);
+  if (CaretEnd < CaretLine.size())
+    CaretLine.erase(CaretEnd, std::string::npos);
   if (FixItInsertionLine.size() > CaretEnd)
     FixItInsertionLine.erase(CaretEnd, std::string::npos);