Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6571,23 +6571,6 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc
if (startTok->str() == startScope->className && startScope->isClassOrStruct() && startTok->strAt(1) != "::")
return startScope->definedType;

if (startTok->isC()) {
const Scope* scope = startScope;
while (scope) {
if (startTok->str() == scope->className && scope->isClassOrStruct())
return scope->definedType;
const Scope* typeScope = scope->findRecordInNestedList(startTok->str(), /*isC*/ true);
if (typeScope) {
if (startTok->str() == typeScope->className && typeScope->isClassOrStruct()) {
if (const Type* type = typeScope->definedType)
return type;
}
}
scope = scope->nestedIn;
}
return nullptr;
}

const Scope* start_scope = startScope;

// absolute path - directly start in global scope
Expand Down
8 changes: 2 additions & 6 deletions test/cfg/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ void g_new_if_test()
};

const struct a * pNew3;
// cppcheck-suppress valueFlowBailoutIncompleteVar
if (pNew3 = g_new(struct a, 6)) {
printf("%p", pNew3);
}
Expand All @@ -305,7 +304,6 @@ void g_new0_test()
int b;
};
// valid
// cppcheck-suppress valueFlowBailoutIncompleteVar
struct a * pNew1 = g_new0(struct a, 5);
printf("%p", pNew1);
g_free(pNew1);
Expand All @@ -324,7 +322,6 @@ void g_try_new_test()
int b;
};
// valid
// cppcheck-suppress valueFlowBailoutIncompleteVar
struct a * pNew1 = g_try_new(struct a, 5);
printf("%p", pNew1);
g_free(pNew1);
Expand All @@ -342,7 +339,6 @@ void g_try_new0_test()
int b;
};
// valid
// cppcheck-suppress valueFlowBailoutIncompleteVar
struct a * pNew1 = g_try_new0(struct a, 5);
printf("%p", pNew1);
g_free(pNew1);
Expand All @@ -360,7 +356,7 @@ void g_renew_test()
struct a {
int b;
};
// cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar]
// cppcheck-suppress leakReturnValNotUsed
g_renew(struct a, NULL, 1);

struct a * pNew = g_new(struct a, 1);
Expand All @@ -375,7 +371,7 @@ void g_try_renew_test()
struct a {
int b;
};
// cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar]
// cppcheck-suppress leakReturnValNotUsed
g_try_renew(struct a, NULL, 1);

struct a * pNew = g_try_new(struct a, 1);
Expand Down
38 changes: 38 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(enum18);
TEST_CASE(enum19);

TEST_CASE(struct1);

TEST_CASE(sizeOfType);

TEST_CASE(isImplicitlyVirtual);
Expand Down Expand Up @@ -6859,6 +6861,42 @@ class TestSymbolDatabase : public TestFixture {
}
}

void struct1() {
GET_SYMBOL_DB_C("struct deer {\n"
" uint16_t a;\n"
" uint16_t b;\n"
"};\n"
"void herd ( void ) {\n"
" struct deer {\n"
" uint16_t a;\n"
" };\n"
"}");

ASSERT_EQUALS("", errout_str());
ASSERT(db);
Comment thread
danmar marked this conversation as resolved.

const Token* deer = Token::findsimplematch(tokenizer.tokens(), "deer {");
ASSERT(deer);
ASSERT(deer->type());
ASSERT(deer->type()->classScope);
const Token* tok = deer->next();
ASSERT(tok->scope());
ASSERT_EQUALS_ENUM(ScopeType::eStruct, tok->scope()->type);
ASSERT_EQUALS(tok, tok->scope()->bodyStart);
ASSERT_EQUALS(tok->scope(), deer->type()->classScope);

const Token* secondDeer = Token::findsimplematch(tok, "deer {");
ASSERT(secondDeer);
ASSERT(secondDeer != deer);
ASSERT(secondDeer->type());
Comment thread
danmar marked this conversation as resolved.
ASSERT(secondDeer->type()->classScope);
tok = secondDeer->next();
ASSERT(tok->scope());
ASSERT_EQUALS_ENUM(ScopeType::eStruct, tok->scope()->type);
ASSERT_EQUALS(tok, tok->scope()->bodyStart);
ASSERT_EQUALS(tok->scope(), secondDeer->type()->classScope);
}

void sizeOfType() {
// #7615 - crash in Symboldatabase::sizeOfType()
GET_SYMBOL_DB("enum e;\n"
Expand Down
Loading