Skip to content

Commit

Permalink
Fix #12393 Stack overflow in accumulateStructMembers() (#5926)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 31, 2024
1 parent f82790d commit 6375880
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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

0 comments on commit 6375880

Please sign in to comment.