Fix crash on garbage code in tokenlist. The corresponding backtrace along with a testcase is hosted at: https://github.com/orbitcowboy/cppcheck_crash_files/blob/master/crash220.cpp

This commit is contained in:
Martin Ettl 2014-09-28 22:04:25 +02:00
parent 38af865560
commit b677d3d17f
2 changed files with 8 additions and 1 deletions

View File

@ -758,6 +758,8 @@ static void compileAnd(Token *&tok, AST_state& state)
while (tok) {
if (tok->str() == "&" && !tok->astOperand1()) {
Token* tok2 = tok->next();
if(!tok2)
break;
if (tok2->str() == "&")
tok2 = tok2->next();
if (state.cpp && Token::Match(tok2, ",|)")) {

View File

@ -50,7 +50,8 @@ private:
TEST_CASE(garbageCode8); // #5511
TEST_CASE(garbageCode9); // #5604
TEST_CASE(garbageCode10); // #6127
TEST_CASE(garbageCode11);
TEST_CASE(astGarbage);
}
@ -232,6 +233,10 @@ private:
void garbageCode10() { // #6127
checkCode("for( rl=reslist; rl!=NULL; rl=rl->next )");
}
void garbageCode11() { // do not crash
checkCode("( ) &");
}
void astGarbage() {
checkCode("--"); // don't crash