From: Manuel Klimek Date: Wed, 13 Aug 2014 14:00:41 +0000 (+0000) Subject: Fix crasher bug in clang-format. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c643eb7a346c2c2f10a799c496c00799828e080;p=clang Fix crasher bug in clang-format. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215549 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index a366234873..9098830161 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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)) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index cc16c33413..15688cdb1b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -9200,5 +9200,9 @@ TEST_F(FormatTest, DisableRegions) { " int k;")); } +TEST_F(FormatTest, DoNotCrashOnInvalidInput) { + format("? ) ="); +} + } // end namespace tooling } // end namespace clang