Symboldatabase::sizeOfType: fix crash; fixes #7615

This commit is contained in:
Matthias Krüger 2016-07-26 01:18:47 +02:00
parent dd766d477d
commit 6fd8edd6e5
2 changed files with 10 additions and 1 deletions

View File

@ -4089,7 +4089,7 @@ unsigned int SymbolDatabase::sizeOfType(const Token *type) const
{ {
unsigned int size = _tokenizer->sizeOfType(type); unsigned int size = _tokenizer->sizeOfType(type);
if (size == 0 && type->type() && type->type()->isEnumType()) { if (size == 0 && type->type() && type->type()->isEnumType() && type->type()->classScope) {
size = _settings->sizeof_int; size = _settings->sizeof_int;
const Token * enum_type = type->type()->classScope->enumType; const Token * enum_type = type->type()->classScope->enumType;
if (enum_type) if (enum_type)

View File

@ -232,6 +232,7 @@ private:
TEST_CASE(garbageCode181); TEST_CASE(garbageCode181);
TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageCode183); // #7505 TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageCode184); // #7615
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
@ -1521,6 +1522,14 @@ private:
ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError); ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError);
} }
// #7615 - crash in Symboldatabase::sizeOfType
void garbageCode184() {
checkCode("enum bar;"
"void foo() {\n"
" bar cats[] = {A, B, C}\n"
" int *bla = cats[ARRAY_SIZE(cats)];\n"
" };\n");
}
}; };
REGISTER_TEST(TestGarbage) REGISTER_TEST(TestGarbage)