diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1d7ea926e..a5a249095 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4089,7 +4089,7 @@ unsigned int SymbolDatabase::sizeOfType(const Token *type) const { 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; const Token * enum_type = type->type()->classScope->enumType; if (enum_type) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 53e07daf7..25b290144 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -232,6 +232,7 @@ private: TEST_CASE(garbageCode181); TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode183); // #7505 + TEST_CASE(garbageCode184); // #7615 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1521,6 +1522,14 @@ private: 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)