]> granicus.if.org Git - clang/commitdiff
Workaround a bug exposed by the FileCheckify of message-length.c, the caret end
authorDaniel Dunbar <daniel@zuster.org>
Mon, 19 Oct 2009 09:11:21 +0000 (09:11 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 19 Oct 2009 09:11:21 +0000 (09:11 +0000)
column computation isn't correct and could exceed the line length, which
resulted in a buffer overflow later.
 - Chris, is there a better way for this code to compute the final column used
   by the caret?

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

lib/Frontend/TextDiagnosticPrinter.cpp
test/Misc/message-length.c

index 63d9a50b368bb7b60039a99fb0cd5e4f1abb2df8..14769c187393871bd8d359012077dc720d27c936 100644 (file)
@@ -214,6 +214,7 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
     // Move the end of the interesting region right until we've
     // pulled in something else interesting.
     if (CaretEnd != SourceLength) {
+      assert(CaretEnd < SourceLength && "Unexpected caret position!");
       unsigned NewEnd = CaretEnd;
 
       // Skip over any whitespace we see here; we're looking for
@@ -320,6 +321,11 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
   while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
     ++LineEnd;
 
+  // FIXME: This shouldn't be necessary, but the CaretEndColNo can extend past
+  // the source line length as currently being computed. See
+  // test/Misc/message-length.c.
+  CaretEndColNo = std::min(CaretEndColNo, unsigned(LineEnd - LineStart));
+
   // Copy the line of code into an std::string for ease of manipulation.
   std::string SourceLine(LineStart, LineEnd);
 
index 69a5c1c191368b140be7993e06f50fcc4f4f84e4..9f4d66fe71c0288f4dd801b64e9b3b5e0ddfe771 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -fmessage-length=72 %s 2>&1 | tee /tmp/out.txt | FileCheck -strict-whitespace %s &&
+// RUN: clang -fsyntax-only -fmessage-length=72 %s 2>&1 | FileCheck -strict-whitespace %s &&
 // RUN: clang -fsyntax-only -fmessage-length=1 %s
 
 // Hack so we can check things better, force the file name and line.
@@ -29,4 +29,4 @@ void a_very_long_line(int *ip, float *FloatPointer) {
 
 
 // CHECK: FILE:23:78
-// CHECK: {{^  ...some long comment text and a brace, eh {} $}}
+// CHECK: {{^  ...// some long comment text and a brace, eh {} $}}