Fix issue 9709: ValueFlow: variable value is not known (#2643)

This commit is contained in:
Paul Fultz II 2020-05-14 07:10:32 -05:00 committed by GitHub
parent 4afaff059b
commit d123279fc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -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() == "{") {

View File

@ -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() {