Ticket #6187: Avoid infinite loop if eraseDeadCode does not remove anything (this time without memory corruption).

This commit is contained in:
Simon Martin 2014-10-22 20:25:36 +02:00
parent dd6ade9831
commit c6e2107d99
2 changed files with 16 additions and 3 deletions

View File

@ -8967,10 +8967,13 @@ void Tokenizer::simplifyWhile0()
// remove "while (0) { .. }"
if (Token::simpleMatch(tok->next()->link(), ") {")) {
Token *end = tok->next()->link();
Token *end = tok->next()->link(), *old_prev = tok->previous();
end = end->next()->link();
tok = tok->previous();
eraseDeadCode(tok, end->next());
eraseDeadCode(old_prev, 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 ) ; }",
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() {