]> granicus.if.org Git - clang/commitdiff
Fix crasher bug in clang-format.
authorManuel Klimek <klimek@google.com>
Wed, 13 Aug 2014 14:00:41 +0000 (14:00 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 13 Aug 2014 14:00:41 +0000 (14:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215549 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index a3662348736c48e991a41cab75d16b43ece9322e..909883016115505ebc4efdcadbd45b846b884d80 100644 (file)
@@ -701,8 +701,11 @@ private:
       for (FormatToken *Previous = Current.Previous;
            Previous && !Previous->isOneOf(tok::comma, tok::semi);
            Previous = Previous->Previous) {
-        if (Previous->isOneOf(tok::r_square, tok::r_paren))
+        if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
           Previous = Previous->MatchingParen;
+          if (!Previous)
+            break;
+        }
         if ((Previous->Type == TT_BinaryOperator ||
              Previous->Type == TT_UnaryOperator) &&
             Previous->isOneOf(tok::star, tok::amp)) {
index cc16c334135048ba2f79c4e4f8bfb93d6554b838..15688cdb1bde031a64c30a801d91a33538a529a4 100644 (file)
@@ -9200,5 +9200,9 @@ TEST_F(FormatTest, DisableRegions) {
                    "   int   k;"));
 }
 
+TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
+  format("? ) =");
+}
+
 } // end namespace tooling
 } // end namespace clang