From a9f7572a6c834a2e34b2f3b016b94330efadfb5b Mon Sep 17 00:00:00 2001 From: yhirose Date: Tue, 30 Mar 2021 20:59:17 -0400 Subject: [PATCH] Fixed Infinite loop 9 problem --- peglib.h | 6 ++++++ test/test2.cc | 37 ++++--------------------------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/peglib.h b/peglib.h index f42f689..a04dfad 100644 --- a/peglib.h +++ b/peglib.h @@ -2945,6 +2945,12 @@ inline void DetectInfiniteLoop::visit(Reference &ope) { ope.rule_->accept(*this); refs_.pop_back(); } + + if (ope.is_macro_) { + for (auto arg : ope.args_) { + arg->accept(*this); + } + } } inline void ReferenceChecker::visit(Reference &ope) { diff --git a/test/test2.cc b/test/test2.cc index 768dac1..3fe8a29 100644 --- a/test/test2.cc +++ b/test/test2.cc @@ -168,39 +168,10 @@ TEST_CASE("Infinite loop 8", "[infinite loop]") { REQUIRE(!pg); } -TEST_CASE("Infinite 9", "[infinite loop]") { - parser pg(R"( -START <- __? SECTION* - -SECTION <- HEADER __ ENTRIES __? - -HEADER <- '[' _ CATEGORY (':' _ ATTRIBUTES)? ']'^header - -CATEGORY <- < [-_a-zA-Z0-9\u0080-\uFFFF ]+ > _ -ATTRIBUTES <- ATTRIBUTE (',' _ ATTRIBUTE)* -ATTRIBUTE <- < [-_a-zA-Z0-9\u0080-\uFFFF]+ > _ - -ENTRIES <- (ENTRY (__ ENTRY)*)? - -ENTRY <- ONE_WAY PHRASE ('|' _ PHRASE)* !'=' - / PHRASE ('|' _ PHRASE)+ !'=' - / %recover(entry) - -ONE_WAY <- PHRASE '=' _ -PHRASE <- WORD (' ' WORD)* _ -WORD <- < (![ \t\r\n=|[\]#] .)+ > - -~__ <- _ (comment? nl _)+ -~_ <- [ \t]* - -comment <- ('#' (!nl .)*) -nl <- '\r'? '\n' - -header <- (!__ .)* { message "invalid section header, missing ']'." } - -# The `(!(__ / HEADER) )+` should be `(!(__ / HEADER) .)+` -entry <- (!(__ / HEADER) )+ { message "invalid token '%t', expecting another phrase." } - )"); +TEST_CASE("Infinite loop 9", "[infinite loop]") { + parser pg(R"( + ROOT <- %recover(('A' /)*) + )"); REQUIRE(!pg); }