r177527 - Fix infinite-loop in unwrapped line parser.

Daniel Jasper djasper at google.com
Wed Mar 20 08:12:38 PDT 2013


Author: djasper
Date: Wed Mar 20 10:12:38 2013
New Revision: 177527

URL: http://llvm.org/viewvc/llvm-project?rev=177527&view=rev
Log:
Fix infinite-loop in unwrapped line parser.

Discovered when accidentally formatting a python file :-).

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=177527&r1=177526&r2=177527&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar 20 10:12:38 2013
@@ -684,7 +684,7 @@ void UnwrappedLineParser::parseRecord()
     // (this would still leave us with an ambiguity between template function
     // and class declarations).
     if (FormatTok.Tok.is(tok::colon) || FormatTok.Tok.is(tok::less)) {
-      while (FormatTok.Tok.isNot(tok::l_brace)) {
+      while (!eof() && FormatTok.Tok.isNot(tok::l_brace)) {
         if (FormatTok.Tok.is(tok::semi))
           return;
         nextToken();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177527&r1=177526&r2=177527&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 20 10:12:38 2013
@@ -2544,6 +2544,9 @@ TEST_F(FormatTest, UnderstandContextOfRe
                "  class X x;\n"
                "else\n"
                "  f();\n");
+
+  // This is simply incomplete. Formatting is not important, but must not crash.
+  verifyFormat("class A:"); 
 }
 
 TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) {





More information about the cfe-commits mailing list