From 6fe554eb4e7075cbfda927c4747d7346a27637f1 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 20 Mar 2013 15:12:38 +0000 Subject: [PATCH] Fix infinite-loop in unwrapped line parser. Discovered when accidentally formatting a python file :-). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177527 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 2 +- unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 2ca44620c3..a01344c03e 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -684,7 +684,7 @@ void UnwrappedLineParser::parseRecord() { // (this would still leave us with an ambiguity between template function // and class declarations). if (FormatTok.Tok.is(tok::colon) || FormatTok.Tok.is(tok::less)) { - while (FormatTok.Tok.isNot(tok::l_brace)) { + while (!eof() && FormatTok.Tok.isNot(tok::l_brace)) { if (FormatTok.Tok.is(tok::semi)) return; nextToken(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 40f09539e7..2a3d66dfd7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2544,6 +2544,9 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { " class X x;\n" "else\n" " f();\n"); + + // This is simply incomplete. Formatting is not important, but must not crash. + verifyFormat("class A:"); } TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) { -- 2.40.0