Ticket #6703: Rewrite pattern in SymbolDatabase to avoid crash upon garbage code.

This commit is contained in:
Simon Martin 2015-05-23 23:18:59 +02:00
parent 1eba077c24
commit 898ba783bf
2 changed files with 6 additions and 1 deletions

View File

@ -75,7 +75,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
if (tok2->next()->str() == ";")
tok = tok2->next();
else if (Token::simpleMatch(tok2->next(), "= {") &&
tok2->linkAt(2)->next()->str() == ";")
Token::simpleMatch(tok2->linkAt(2), "} ;"))
tok = tok2->linkAt(2)->next();
else if (Token::Match(tok2->next(), "(|{") &&
tok2->next()->link()->strAt(1) == ";")

View File

@ -81,6 +81,7 @@ private:
TEST_CASE(garbageCode40); // #6620
TEST_CASE(garbageCode41); // #6685
TEST_CASE(garbageCode42); // #5760
TEST_CASE(garbageCode43); // #6703
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -470,6 +471,10 @@ private:
ASSERT_THROW(checkCode("{ } * const ( ) { }"), InternalError);
}
void garbageCode43() { // #6703
checkCode("int { }; struct A<void> a = { }");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"