From f088588c883212961eb2c5af21588e7701ab2907 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 28 Sep 2014 17:38:34 +0200 Subject: [PATCH] Ticket #6187: Avoid infinite loop if eraseDeadCode does not remove anything (invalid goto into a dead loop's body). --- lib/tokenize.cpp | 3 +-- test/testsimplifytokens.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ebded488c..9e3b39516 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9066,8 +9066,7 @@ void Tokenizer::simplifyWhile0() if (Token::simpleMatch(tok->next()->link(), ") {")) { Token *end = tok->next()->link(); end = end->next()->link(); - tok = tok->previous(); - eraseDeadCode(tok, end->next()); + eraseDeadCode(tok->previous(), end->next()); } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 759f2640e..1a94ce708 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2372,6 +2372,16 @@ private: ASSERT_EQUALS("void foo ( ) { exit ( 0 ) ; }", tokWithStdLib("void foo() { do { exit(0); } while (true); }")); + + // #6187 + tokWithStdLib("void foo() {\n" + " goto label;\n" + " for (int i = 0; i < 0; ++i) {\n" + " ;\n" + "label:\n" + " ;\n" + " }\n" + "}"); } void strcat1() {