Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3606,6 +3606,8 @@ static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase&
continue;
if (tok->astOperand2()->exprId() == 0)
continue;
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->isArray() && tok->astOperand2()->variable()->getTypeName() != "std::array") // array to pointer decay

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also check its being assigned to a pointer: astIsPointer(tok->astOperand1()).

Also I dont really see the point in checking for std::array, and its probably better to not check just in case a future version of C++ add implicit conversions to support pointer-like decaying behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually even better would be to compare the pointer rank if it matches: tok->astOperand1()->valueType().pointer != tok->astOperand2()->valueType().pointer

continue;
if (!isConstExpression(tok->astOperand2(), settings.library))
continue;
if (tok->astOperand1()->valueType() && tok->astOperand2()->valueType()) {
Expand Down
9 changes: 9 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9092,6 +9092,15 @@ class TestValueFlow : public TestFixture {
" return x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, "malloc(10)", 0));

code = "struct S {\n" // #14891
" void f() const {\n"
" const int* p = a;\n"
" if (*p) {}\n"
" }\n"
" int a[3];\n"
"};\n";
ASSERT(tokenValues(code, "* p )").empty());
}

void valueFlowSymbolicIdentity()
Expand Down
Loading