[cfe-commits] r84475 - in /cfe/trunk: lib/Frontend/TextDiagnosticPrinter.cpp test/Misc/message-length.c
Daniel Dunbar
daniel at zuster.org
Mon Oct 19 02:11:24 PDT 2009
Author: ddunbar
Date: Mon Oct 19 04:11:21 2009
New Revision: 84475
URL: http://llvm.org/viewvc/llvm-project?rev=84475&view=rev
Log:
Workaround a bug exposed by the FileCheckify of message-length.c, the caret end
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?
Modified:
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/test/Misc/message-length.c
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=84475&r1=84474&r2=84475&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Mon Oct 19 04:11:21 2009
@@ -214,6 +214,7 @@
// 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 @@
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);
Modified: cfe/trunk/test/Misc/message-length.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/message-length.c?rev=84475&r1=84474&r2=84475&view=diff
==============================================================================
--- cfe/trunk/test/Misc/message-length.c (original)
+++ cfe/trunk/test/Misc/message-length.c Mon Oct 19 04:11:21 2009
@@ -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 @@
// CHECK: FILE:23:78
-// CHECK: {{^ ...some long comment text and a brace, eh {} $}}
+// CHECK: {{^ ...// some long comment text and a brace, eh {} $}}
More information about the cfe-commits
mailing list