Skip to content

Commit d123279

Browse files
authored
Fix issue 9709: ValueFlow: variable value is not known (cppcheck-opensource#2643)
1 parent 4afaff0 commit d123279

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/programmemory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
199199
else
200200
pm.setUnknown(vartok->varId());
201201
}
202+
} else if (!setvar && Token::Match(tok2, "%var% !!=") && isVariableChanged(tok2, 0, nullptr, true)) {
203+
const Token *vartok = tok2;
204+
if (!pm.hasValue(vartok->varId()))
205+
pm.setUnknown(vartok->varId());
202206
}
203207

204208
if (tok2->str() == "{") {

test/testcondition.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3366,6 +3366,18 @@ class TestCondition : public TestFixture {
33663366
" if (!x) {}\n"
33673367
"}\n");
33683368
ASSERT_EQUALS("", errout.str());
3369+
3370+
// #9709
3371+
check("void f(int a) {\n"
3372+
" bool ok = false;\n"
3373+
" const char * r = nullptr;\n"
3374+
" do_something(&r);\n"
3375+
" if (r != nullptr)\n"
3376+
" ok = a != 0;\n"
3377+
" if (ok) {}\n"
3378+
"}\n");
3379+
ASSERT_EQUALS("", errout.str());
3380+
33693381
}
33703382

33713383
void alwaysTrueInfer() {

0 commit comments

Comments
 (0)