Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12393 Stack overflow in accumulateStructMembers() #5926

Merged
merged 3 commits into from
Jan 31, 2024
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
2 changes: 2 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7201,6 +7201,8 @@ static const Token* parsedecl(const Token* type,
if (!type->originalName().empty())
valuetype->originalTypeName = type->originalName();
type = type->next();
if (type && type->link() && type->str() == "<")
type = type->link()->next();
}

// Set signedness for integral types..
Expand Down
21 changes: 21 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(VariableValueType4); // smart pointer type
TEST_CASE(VariableValueType5); // smart pointer type
TEST_CASE(VariableValueTypeReferences);
TEST_CASE(VariableValueTypeTemplate);

TEST_CASE(findVariableType1);
TEST_CASE(findVariableType2);
Expand Down Expand Up @@ -1370,6 +1371,26 @@ class TestSymbolDatabase : public TestFixture {
}
}

void VariableValueTypeTemplate() {
{
GET_SYMBOL_DB("template <class T>\n" // #12393
"struct S {\n"
" struct U {\n"
" S<T>* p;\n"
" };\n"
" U u;\n"
"};\n");
const Variable* const p = db->getVariableFromVarId(1);
ASSERT_EQUALS(p->name(), "p");
ASSERT(p->valueType());
ASSERT(p->valueType()->pointer == 1);
ASSERT(p->valueType()->constness == 0);
ASSERT(p->valueType()->reference == Reference::None);
ASSERT_EQUALS(p->scope()->className, "U");
ASSERT_EQUALS(p->typeScope()->className, "S");
}
}

void findVariableType1() {
GET_SYMBOL_DB("class A {\n"
"public:\n"
Expand Down
10 changes: 10 additions & 0 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ class TestType : public TestFixture {
" long long j = *(p++);\n"
"}\n", settings);
ASSERT_EQUALS("", errout.str());

check("template <class T>\n" // #12393
"struct S {\n"
" S& operator=(const S&) { return *this; }\n"
" struct U {\n"
" S<T>* p;\n"
" };\n"
" U u;\n"
"};\n", settings);
ASSERT_EQUALS("", errout.str()); // don't crash
}

void longCastReturn() {
Expand Down
Loading