Skip to content

Commit 86f4c91

Browse files
Fix #14864 FN knownConditionTrueFalse with default initialized user type pointer (#8672)
1 parent b37e6b8 commit 86f4c91

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,8 @@ static bool isVariableInit(const Token *tok)
40994099
return false;
41004100
if (var->nameToken() != tok->astOperand1())
41014101
return false;
4102+
if (var->isPointer())
4103+
return true;
41024104
const ValueType* vt = var->valueType();
41034105
if (!vt)
41044106
return false;

test/testvalueflow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,6 +3188,18 @@ class TestValueFlow : public TestFixture {
31883188
" return x;\n"
31893189
"}\n";
31903190
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, -1));
3191+
3192+
code = "A* f() {\n" // #14864
3193+
" A* x{};\n"
3194+
" return x;\n"
3195+
"}\n";
3196+
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 0));
3197+
3198+
code = "A* f() {\n"
3199+
" A* x{ nullptr };\n"
3200+
" return x;\n"
3201+
"}\n";
3202+
ASSERT_EQUALS(true, testValueOfXKnown(code, 3U, 0));
31913203
}
31923204

31933205
void valueFlowAfterSwap()

0 commit comments

Comments
 (0)