#7228 segmentation fault (invalid code) in Tokenizer::isFunctionHead

This commit is contained in:
Alexander Mai 2015-12-26 00:21:56 +01:00
parent ab6809f3fa
commit 87767fb666
2 changed files with 8 additions and 0 deletions

View File

@ -54,6 +54,8 @@ namespace {
const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &endsWith) const const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &endsWith) const
{ {
if (!tok)
return nullptr;
if (tok->str() == "(") if (tok->str() == "(")
tok = tok->link(); tok = tok->link();
if (Token::Match(tok, ") const| [;:{]")) { if (Token::Match(tok, ") const| [;:{]")) {

View File

@ -211,6 +211,7 @@ private:
TEST_CASE(garbageCode160); // #7190 TEST_CASE(garbageCode160); // #7190
TEST_CASE(garbageCode161); // #7200 TEST_CASE(garbageCode161); // #7200
TEST_CASE(garbageCode162); // #7208 TEST_CASE(garbageCode162); // #7208
TEST_CASE(garbageCode163); // #7228
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
@ -1393,6 +1394,11 @@ private:
ASSERT_THROW(checkCode("return << >> x return << >> x ", false), InternalError); ASSERT_THROW(checkCode("return << >> x return << >> x ", false), InternalError);
} }
void garbageCode163() {
//7228
ASSERT_THROW(checkCode("typedef s f[](){typedef d h(;f)}", false), InternalError);
}
}; };
REGISTER_TEST(TestGarbage) REGISTER_TEST(TestGarbage)