Ticket #6187: Avoid infinite loop if eraseDeadCode does not remove anything (invalid goto into a dead loop's body).

This commit is contained in:
Simon Martin 2014-09-28 17:38:34 +02:00
parent ccd80e3407
commit f088588c88
2 changed files with 11 additions and 2 deletions

View File

@ -9066,8 +9066,7 @@ void Tokenizer::simplifyWhile0()
if (Token::simpleMatch(tok->next()->link(), ") {")) { if (Token::simpleMatch(tok->next()->link(), ") {")) {
Token *end = tok->next()->link(); Token *end = tok->next()->link();
end = end->next()->link(); end = end->next()->link();
tok = tok->previous(); eraseDeadCode(tok->previous(), end->next());
eraseDeadCode(tok, end->next());
} }
} }
} }

View File

@ -2372,6 +2372,16 @@ private:
ASSERT_EQUALS("void foo ( ) { exit ( 0 ) ; }", ASSERT_EQUALS("void foo ( ) { exit ( 0 ) ; }",
tokWithStdLib("void foo() { do { exit(0); } while (true); }")); 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() { void strcat1() {