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

Another fix for #12393 Stack overflow in accumulateStructMembers() #5934

Merged
merged 1 commit into from
Feb 2, 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
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
Loading