SymbolDatabase: Fix crash if std::shared_ptr type is only forwarded, not defined

This commit is contained in:
Daniel Marjamäki 2019-10-20 17:00:15 +02:00
parent e50b9e2bef
commit 82d8f3e7f5
2 changed files with 13 additions and 1 deletions

View File

@ -1175,7 +1175,8 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers()
fixVarId(varIds, tok, const_cast<Token *>(membertok), membervar); fixVarId(varIds, tok, const_cast<Token *>(membertok), membervar);
} }
} else if (const ::Type *type = var ? var->smartPointerType() : nullptr) { } else if (const ::Type *type = var ? var->smartPointerType() : nullptr) {
const Variable *membervar = type->classScope->getVariable(membertok->str()); const Scope *classScope = type->classScope;
const Variable *membervar = classScope ? classScope->getVariable(membertok->str()) : nullptr;
if (membervar) { if (membervar) {
membertok->variable(membervar); membertok->variable(membervar);
if (membertok->varId() == 0 || mVariableList[membertok->varId()] == nullptr) if (membertok->varId() == 0 || mVariableList[membertok->varId()] == nullptr)

View File

@ -352,6 +352,7 @@ private:
TEST_CASE(findFunction27); TEST_CASE(findFunction27);
TEST_CASE(findFunction28); TEST_CASE(findFunction28);
TEST_CASE(findFunction29); TEST_CASE(findFunction29);
TEST_CASE(findFunction30);
TEST_CASE(findFunctionContainer); TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC); TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo TEST_CASE(findFunctionGlobalScope); // ::foo
@ -5776,6 +5777,16 @@ private:
ASSERT_EQUALS(2, foo->function()->token->linenr()); ASSERT_EQUALS(2, foo->function()->token->linenr());
} }
void findFunction30() {
GET_SYMBOL_DB("struct A;\n"
"void foo(std::shared_ptr<A> ptr) {\n"
" int x = ptr->bar();\n"
"}");
const Token *bar = Token::findsimplematch(tokenizer.tokens(), "bar ( ) ;");
ASSERT(bar);
ASSERT(!bar->function());
}
void findFunctionContainer() { void findFunctionContainer() {
{ {
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n" GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"