Skip to content

Commit

Permalink
Another fix for #12393 Stack overflow in accumulateStructMembers() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Feb 2, 2024
1 parent 63ac630 commit 998ffe3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ static size_t bitCeil(size_t x)

static size_t getAlignOf(const ValueType& vt, const Settings& settings)
{
if (vt.pointer || vt.isPrimitive()) {
if (vt.pointer || vt.reference != Reference::None || vt.isPrimitive()) {
auto align = ValueFlow::getSizeOf(vt, settings);
return align == 0 ? 0 : bitCeil(align);
}
Expand All @@ -1161,7 +1161,7 @@ static nonneg int getSizeOfType(const Token *typeTok, const Settings &settings)

size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings)
{
if (vt.pointer)
if (vt.pointer || vt.reference != Reference::None)
return settings.platform.sizeof_pointer;
if (vt.type == ValueType::Type::BOOL || vt.type == ValueType::Type::CHAR)
return 1;
Expand Down
10 changes: 10 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,16 @@ class TestValueFlow : public TestFixture {
values = tokenValues(code, "( X )");
ASSERT_EQUALS(1U, values.size());
ASSERT_EQUALS(12, values.back().intvalue);

code = "struct T;\n"
"struct S { T& r; };\n"
"struct T { S s{ *this }; };\n"
"void f() {\n"
" sizeof(T) == sizeof(void*);\n"
"}\n";
values = tokenValues(code, "==");
ASSERT_EQUALS(1U, values.size());
ASSERT_EQUALS(1LL, values.back().intvalue);
}

void valueFlowComma()
Expand Down

0 comments on commit 998ffe3

Please sign in to comment.