From 8bfccb963b3519393c0266b452a115a4bb46d207 Mon Sep 17 00:00:00 2001 From: owenca Date: Sat, 21 May 2022 10:28:54 -0700 Subject: [PATCH] [clang-format] Fix an infinite loop in parseJavaEnumBody() Fixes #55623. --- clang/lib/Format/UnwrappedLineParser.cpp | 2 +- clang/unittests/Format/FormatTestJava.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index be081a9..18f476a 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3509,7 +3509,7 @@ void UnwrappedLineParser::parseJavaEnumBody() { ++Line->Level; // Parse the enum constants. - while (FormatTok) { + while (FormatTok->isNot(tok::eof)) { if (FormatTok->is(tok::l_brace)) { // Parse the constant's class body. parseBlock(/*MustBeDeclaration=*/true, /*AddLevels=*/1u, diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index e778836e..03e16ae 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -198,6 +198,8 @@ TEST_F(FormatTestJava, EnumDeclarations) { " void f() {}\n" "}"); verifyFormat("enum SomeThing {\n" + " void f() {}"); + verifyFormat("enum SomeThing {\n" " ABC(1, \"ABC\"),\n" " CDE(2, \"CDE\");\n" " Something(int i, String s) {}\n" -- 2.7.4