diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a3662348736..90988301611 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index cc16c334135..15688cdb1bd 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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 |