From: Daniel Jasper Date: Mon, 19 Jan 2015 11:49:32 +0000 (+0000) Subject: clang-format: Fix crasher on weird comments. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b79efb51f9ec9d6847a7373092c5006da2eeae1;p=platform%2Fupstream%2Fllvm.git clang-format: Fix crasher on weird comments. Crashing input: /\ / comment llvm-svn: 226454 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 58902bf..df6bfd3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -838,10 +838,8 @@ private: (!Current.Previous || Current.Previous->isNot(tok::l_square))) { Current.Type = TT_BinaryOperator; } else if (Current.is(tok::comment)) { - if (Current.TokenText.startswith("//")) - Current.Type = TT_LineComment; - else - Current.Type = TT_BlockComment; + Current.Type = + Current.TokenText.startswith("/*") ? TT_BlockComment : TT_LineComment; } else if (Current.is(tok::r_paren)) { if (rParenEndsCast(Current)) Current.Type = TT_CastRParen; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f267c94..615b46a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1035,6 +1035,9 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) { " // spanning two lines\n" " x + 3) {\n" "}")); + + verifyNoCrash("/\\\n/"); + verifyNoCrash("/\\\n* */"); } TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {