Merge pull request #456 from simartin/ticket_6817_take2

Ticket #6187: Avoid infinite loop if eraseDeadCode does not remove anything (this time without memory corruption).
This commit is contained in:
Daniel Marjamäki 2014-10-23 09:43:02 +02:00
commit 6088ba7951
2 changed files with 16 additions and 3 deletions

View File

@ -8967,10 +8967,13 @@ void Tokenizer::simplifyWhile0()
// remove "while (0) { .. }" // remove "while (0) { .. }"
if (Token::simpleMatch(tok->next()->link(), ") {")) { if (Token::simpleMatch(tok->next()->link(), ") {")) {
Token *end = tok->next()->link(); Token *end = tok->next()->link(), *old_prev = tok->previous();
end = end->next()->link(); end = end->next()->link();
tok = tok->previous(); eraseDeadCode(old_prev, end->next());
eraseDeadCode(tok, end->next()); if (old_prev && old_prev->next())
tok = old_prev->next();
else
break;
} }
} }
} }

View File

@ -2393,6 +2393,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() {