Skip to content

Commit 6375880

Browse files
Fix #12393 Stack overflow in accumulateStructMembers() (#5926)
1 parent f82790d commit 6375880

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7201,6 +7201,8 @@ static const Token* parsedecl(const Token* type,
72017201
if (!type->originalName().empty())
72027202
valuetype->originalTypeName = type->originalName();
72037203
type = type->next();
7204+
if (type && type->link() && type->str() == "<")
7205+
type = type->link()->next();
72047206
}
72057207

72067208
// Set signedness for integral types..

test/testsymboldatabase.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class TestSymbolDatabase : public TestFixture {
225225
TEST_CASE(VariableValueType4); // smart pointer type
226226
TEST_CASE(VariableValueType5); // smart pointer type
227227
TEST_CASE(VariableValueTypeReferences);
228+
TEST_CASE(VariableValueTypeTemplate);
228229

229230
TEST_CASE(findVariableType1);
230231
TEST_CASE(findVariableType2);
@@ -1370,6 +1371,26 @@ class TestSymbolDatabase : public TestFixture {
13701371
}
13711372
}
13721373

1374+
void VariableValueTypeTemplate() {
1375+
{
1376+
GET_SYMBOL_DB("template <class T>\n" // #12393
1377+
"struct S {\n"
1378+
" struct U {\n"
1379+
" S<T>* p;\n"
1380+
" };\n"
1381+
" U u;\n"
1382+
"};\n");
1383+
const Variable* const p = db->getVariableFromVarId(1);
1384+
ASSERT_EQUALS(p->name(), "p");
1385+
ASSERT(p->valueType());
1386+
ASSERT(p->valueType()->pointer == 1);
1387+
ASSERT(p->valueType()->constness == 0);
1388+
ASSERT(p->valueType()->reference == Reference::None);
1389+
ASSERT_EQUALS(p->scope()->className, "U");
1390+
ASSERT_EQUALS(p->typeScope()->className, "S");
1391+
}
1392+
}
1393+
13731394
void findVariableType1() {
13741395
GET_SYMBOL_DB("class A {\n"
13751396
"public:\n"

test/testtype.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,16 @@ class TestType : public TestFixture {
403403
" long long j = *(p++);\n"
404404
"}\n", settings);
405405
ASSERT_EQUALS("", errout.str());
406+
407+
check("template <class T>\n" // #12393
408+
"struct S {\n"
409+
" S& operator=(const S&) { return *this; }\n"
410+
" struct U {\n"
411+
" S<T>* p;\n"
412+
" };\n"
413+
" U u;\n"
414+
"};\n", settings);
415+
ASSERT_EQUALS("", errout.str()); // don't crash
406416
}
407417

408418
void longCastReturn() {

0 commit comments

Comments
 (0)