Skip to content

Commit 3daba5f

Browse files
Fix #14891 FP knownConditionTrueFalse (dereferencing pointer to array member) (#8704)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 1ef5ef3 commit 3daba5f

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,6 +3606,9 @@ static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase&
36063606
continue;
36073607
if (tok->astOperand2()->exprId() == 0)
36083608
continue;
3609+
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->isArray() &&
3610+
tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->pointer) // array to pointer decay
3611+
continue;
36093612
if (!isConstExpression(tok->astOperand2(), settings.library))
36103613
continue;
36113614
if (tok->astOperand1()->valueType() && tok->astOperand2()->valueType()) {

test/testvalueflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9225,6 +9225,15 @@ class TestValueFlow : public TestFixture {
92259225
" return x;\n"
92269226
"}\n";
92279227
ASSERT_EQUALS(false, testValueOfX(code, 3U, "malloc(10)", 0));
9228+
9229+
code = "struct S {\n" // #14891
9230+
" void f() const {\n"
9231+
" const int* p = a;\n"
9232+
" if (*p) {}\n"
9233+
" }\n"
9234+
" int a[3];\n"
9235+
"};\n";
9236+
ASSERT(tokenValues(code, "* p )").empty());
92289237
}
92299238

92309239
void valueFlowSymbolicIdentity()

0 commit comments

Comments
 (0)