From: Dmitri Gribenko Date: Wed, 27 Jun 2012 23:28:29 +0000 (+0000) Subject: Fix an infinite loop in comment lexer: we were not advancing in the input character... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5676d32a23faf0506f5c295980c2876c862488d5;p=clang Fix an infinite loop in comment lexer: we were not advancing in the input character stream when we saw a '<' that is not a start of an HTML tag. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159303 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/CommentLexer.cpp b/lib/AST/CommentLexer.cpp index 0b76050ff0..c3a801d924 100644 --- a/lib/AST/CommentLexer.cpp +++ b/lib/AST/CommentLexer.cpp @@ -357,6 +357,11 @@ void Lexer::lexCommentText(Token &T) { setupAndLexHTMLOpenTag(T); else if (C == '/') lexHTMLCloseTag(T); + else { + StringRef Text(BufferPtr, TokenPtr - BufferPtr); + formTokenWithChars(T, TokenPtr, tok::text); + T.setText(Text); + } return; } diff --git a/unittests/AST/CommentLexer.cpp b/unittests/AST/CommentLexer.cpp index a1e2427880..5b4712df25 100644 --- a/unittests/AST/CommentLexer.cpp +++ b/unittests/AST/CommentLexer.cpp @@ -683,6 +683,28 @@ TEST_F(CommentLexerTest, HTML1) { } TEST_F(CommentLexerTest, HTML2) { + const char *Source = + "// < tag"; + + std::vector Toks; + + lexString(Source, Toks); + + ASSERT_EQ(4U, Toks.size()); + + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); + + ASSERT_EQ(tok::text, Toks[1].getKind()); + ASSERT_EQ(StringRef("<"), Toks[1].getText()); + + ASSERT_EQ(tok::text, Toks[2].getKind()); + ASSERT_EQ(StringRef(" tag"), Toks[2].getText()); + + ASSERT_EQ(tok::newline, Toks[3].getKind()); +} + +TEST_F(CommentLexerTest, HTML3) { const char *Sources[] = { "// Toks; @@ -726,7 +748,7 @@ TEST_F(CommentLexerTest, HTML3) { ASSERT_EQ(tok::newline, Toks[3].getKind()); } -TEST_F(CommentLexerTest, HTML4) { +TEST_F(CommentLexerTest, HTML5) { const char *Sources[] = { "// Toks; @@ -839,7 +861,7 @@ TEST_F(CommentLexerTest, HTML7) { ASSERT_EQ(tok::newline, Toks[5].getKind()); } -TEST_F(CommentLexerTest, HTML8) { +TEST_F(CommentLexerTest, HTML9) { const char *Sources[] = { "// ", "// " @@ -905,7 +927,7 @@ TEST_F(CommentLexerTest, HTML9) { } } -TEST_F(CommentLexerTest, HTML10) { +TEST_F(CommentLexerTest, HTML11) { const char *Source = "// Toks; @@ -924,7 +946,7 @@ TEST_F(CommentLexerTest, HTML10) { } -TEST_F(CommentLexerTest, HTML11) { +TEST_F(CommentLexerTest, HTML12) { const char *Source = "// Toks; @@ -945,7 +967,7 @@ TEST_F(CommentLexerTest, HTML11) { ASSERT_EQ(tok::newline, Toks[3].getKind()); } -TEST_F(CommentLexerTest, HTML12) { +TEST_F(CommentLexerTest, HTML13) { const char *Sources[] = { "// ",