From: Daniel Jasper Date: Mon, 19 Jan 2015 11:49:32 +0000 (+0000) Subject: clang-format: Fix crasher on weird comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25b834d9ed41ba3eed4afe43997a293e21ccff68;p=clang clang-format: Fix crasher on weird comments. Crashing input: /\ / comment git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226454 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 58902bfbd6..df6bfd37ae 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f267c94b6d..615b46a1d4 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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) {