summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2008-08-05 19:40:20 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2008-08-05 19:40:20 +0000
commitd86aa9340d108ef7f21580e7d5f1e73d7d792e58 (patch)
tree2b98803cfe1ce67143d1a1bee827a86bd3adbc61
parent2c674f6dbb086a813b32cd66a8be49407ff4f576 (diff)
downloadbcm5719-llvm-d86aa9340d108ef7f21580e7d5f1e73d7d792e58.tar.gz
bcm5719-llvm-d86aa9340d108ef7f21580e7d5f1e73d7d792e58.zip
fix crash when printing diagnostics with tokens that span through more than one line
llvm-svn: 54365
-rw-r--r--clang/Driver/TextDiagnosticPrinter.cpp13
-rw-r--r--clang/test/Sema/text-diag.c4
2 files changed, 12 insertions, 5 deletions
diff --git a/clang/Driver/TextDiagnosticPrinter.cpp b/clang/Driver/TextDiagnosticPrinter.cpp
index 5d06ebea2d1..16c7645862d 100644
--- a/clang/Driver/TextDiagnosticPrinter.cpp
+++ b/clang/Driver/TextDiagnosticPrinter.cpp
@@ -49,7 +49,7 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
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 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
}
// 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] = '~';
}
diff --git a/clang/test/Sema/text-diag.c b/clang/test/Sema/text-diag.c
new file mode 100644
index 00000000000..2e312918442
--- /dev/null
+++ b/clang/test/Sema/text-diag.c
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only %s
+unsigned char *foo = "texto\
+que continua\
+e continua";
OpenPOWER on IntegriCloud