r226454 - clang-format: Fix crasher on weird comments.
Daniel Jasper
djasper at google.com
Mon Jan 19 03:49:32 PST 2015
Author: djasper
Date: Mon Jan 19 05:49:32 2015
New Revision: 226454
URL: http://llvm.org/viewvc/llvm-project?rev=226454&view=rev
Log:
clang-format: Fix crasher on weird comments.
Crashing input:
/\
/ comment
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=226454&r1=226453&r2=226454&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan 19 05:49:32 2015
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226454&r1=226453&r2=226454&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 19 05:49:32 2015
@@ -1035,6 +1035,9 @@ TEST_F(FormatTest, UnderstandsSingleLine
" // spanning two lines\n"
" x + 3) {\n"
"}"));
+
+ verifyNoCrash("/\\\n/");
+ verifyNoCrash("/\\\n* */");
}
TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {
More information about the cfe-commits
mailing list