From d123279fc13e51ab9cb7d08065558c08103d16d3 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Thu, 14 May 2020 07:10:32 -0500 Subject: [PATCH] Fix issue 9709: ValueFlow: variable value is not known (#2643) --- lib/programmemory.cpp | 4 ++++ test/testcondition.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 770cfd0e1..a6a3f9955 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -199,6 +199,10 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok else pm.setUnknown(vartok->varId()); } + } else if (!setvar && Token::Match(tok2, "%var% !!=") && isVariableChanged(tok2, 0, nullptr, true)) { + const Token *vartok = tok2; + if (!pm.hasValue(vartok->varId())) + pm.setUnknown(vartok->varId()); } if (tok2->str() == "{") { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index b63d7c2b5..dc8c193ae 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3366,6 +3366,18 @@ private: " if (!x) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #9709 + check("void f(int a) {\n" + " bool ok = false;\n" + " const char * r = nullptr;\n" + " do_something(&r);\n" + " if (r != nullptr)\n" + " ok = a != 0;\n" + " if (ok) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void alwaysTrueInfer() {