From: Douglas Gregor Date: Sun, 3 May 2009 15:24:25 +0000 (+0000) Subject: Fix crash in source-line truncation code for diagnostic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2167de4c4934d6beb3af3a4d74ee160def67f74a;p=clang Fix crash in source-line truncation code for diagnostic 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 --- diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 042e894feb..62446f3300 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -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);