Ticket #4994: Don't crash when checking variable scope for invalid input.

This commit is contained in:
Simon Martin 2013-08-31 14:22:06 +02:00
parent 997c9ce100
commit 843833f907
2 changed files with 14 additions and 1 deletions

View File

@ -2254,8 +2254,11 @@ void Scope::getVariableList()
// skip return and delete
else if (Token::Match(tok, "return|delete")) {
while (tok->next() && tok->next()->str() != ";")
while (tok->next() &&
tok->next()->str() != ";" &&
tok->next()->str() != "}" /* ticket #4994 */) {
tok = tok->next();
}
continue;
}

View File

@ -73,6 +73,7 @@ private:
TEST_CASE(varScope16);
TEST_CASE(varScope17);
TEST_CASE(varScope18);
TEST_CASE(varScope19); // Ticket #4994
TEST_CASE(oldStylePointerCast);
TEST_CASE(invalidPointerCast);
@ -1008,6 +1009,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void varScope19() { // Ticket #4994
varScope("long f () {\n"
" return a >> extern\n"
"}\n"
"long a = 1 ;\n"
"long b = 2 ;");
ASSERT_EQUALS("", errout.str());
}
void checkOldStylePointerCast(const char code[]) {
// Clear the error buffer..
errout.str("");