r226450 - clang-format: Fix crash on invalid code.

Daniel Jasper djasper at google.com
Mon Jan 19 02:51:42 PST 2015


Author: djasper
Date: Mon Jan 19 04:51:42 2015
New Revision: 226450

URL: http://llvm.org/viewvc/llvm-project?rev=226450&view=rev
Log:
clang-format: Fix crash on invalid code.

Input "a<," made clang-format crash.

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

Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=226450&r1=226449&r2=226450&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Mon Jan 19 04:51:42 2015
@@ -59,7 +59,8 @@ void TokenRole::precomputeFormattingInfo
 unsigned CommaSeparatedList::formatAfterToken(LineState &State,
                                               ContinuationIndenter *Indenter,
                                               bool DryRun) {
-  if (!State.NextToken->Previous || !State.NextToken->Previous->Previous)
+  if (State.NextToken == nullptr || !State.NextToken->Previous ||
+      !State.NextToken->Previous->Previous)
     return 0;
 
   // Ensure that we start on the opening brace.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226450&r1=226449&r2=226450&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 19 04:51:42 2015
@@ -6038,6 +6038,8 @@ TEST_F(FormatTest, FormatsBracedListsInC
   // No column layout should be used here.
   verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n"
                "                   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};");
+
+  verifyNoCrash("a<,");
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {





More information about the cfe-commits mailing list