]> granicus.if.org Git - clang/commitdiff
Fix infinite-loop in unwrapped line parser.
authorDaniel Jasper <djasper@google.com>
Wed, 20 Mar 2013 15:12:38 +0000 (15:12 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 20 Mar 2013 15:12:38 +0000 (15:12 +0000)
Discovered when accidentally formatting a python file :-).

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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 2ca44620c33c8d4e8e2578dd179744371c1eab59..a01344c03e6998c8b3cb1e61f3dd059635a7270f 100644 (file)
@@ -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();
index 40f09539e7ae28b9fd20ff04717f3446aa3098d0..2a3d66dfd7977d6d183ebc1fcedac1797568714a 100644 (file)
@@ -2544,6 +2544,9 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
                "  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) {