]> granicus.if.org Git - clang/commitdiff
fix crash when printing diagnostics with tokens that span through more than one line
authorNuno Lopes <nunoplopes@sapo.pt>
Tue, 5 Aug 2008 19:40:20 +0000 (19:40 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Tue, 5 Aug 2008 19:40:20 +0000 (19:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54365 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/TextDiagnosticPrinter.cpp
test/Sema/text-diag.c [new file with mode: 0644]

index 5d06ebea2d14c2fb8948660f283805f24d9d63c8..16c7645862da039e1cc711e2eec67a295896904d 100644 (file)
@@ -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/test/Sema/text-diag.c b/test/Sema/text-diag.c
new file mode 100644 (file)
index 0000000..2e31291
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only %s
+unsigned char *foo = "texto\
+que continua\
+e continua";