fix crash when printing diagnostics with tokens that span through more than one line
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54365 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp
index 5d06ebe..16c7645 100644
--- a/Driver/TextDiagnosticPrinter.cpp
+++ b/Driver/TextDiagnosticPrinter.cpp
@@ -49,7 +49,7 @@
SourceManager& SourceMgr,
unsigned LineNo, unsigned FileID,
std::string &CaratLine,
- const std::string &SourceLine) {
+ const std::string &SourceLine) {
assert(CaratLine.size() == SourceLine.size() &&
"Expect a correspondence between source and carat line!");
if (!R.isValid()) return;
@@ -91,13 +91,16 @@
}
// Pick the last non-whitespace column.
- while (EndColNo-1 &&
- (SourceLine[EndColNo-1] == ' ' || SourceLine[EndColNo-1] == '\t'))
- --EndColNo;
+ if (EndColNo <= SourceLine.size())
+ while (EndColNo-1 &&
+ (SourceLine[EndColNo-1] == ' ' || SourceLine[EndColNo-1] == '\t'))
+ --EndColNo;
+ else
+ EndColNo = SourceLine.size();
// Fill the range with ~'s.
assert(StartColNo <= EndColNo && "Invalid range!");
- for (unsigned i = StartColNo; i != EndColNo; ++i)
+ for (unsigned i = StartColNo; i < EndColNo; ++i)
CaratLine[i] = '~';
}