Fix 10956: ValueFlow: Incorrect value when assigned to two variables (#4019)

* Fix 10956: ValueFlow: Incorrect value when assigned to two variables

* Format
This commit is contained in:
Paul Fultz II 2022-04-14 00:35:07 -05:00 committed by GitHub
parent 7721cd14b6
commit 09597bc7e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 15 deletions

View File

@ -786,20 +786,6 @@ static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Sett
return v; return v;
if (pm.hasValue(expr->exprId())) if (pm.hasValue(expr->exprId()))
return pm.at(expr->exprId()); return pm.at(expr->exprId());
// Find symbolic values
for (const ValueFlow::Value& value : expr->values()) {
if (!value.isSymbolicValue())
continue;
// TODO: Handle possible symbolic values
if (!value.isKnown())
continue;
if (!pm.hasValue(value.tokvalue->exprId()))
continue;
ValueFlow::Value v2 = pm.at(value.tokvalue->exprId());
v2.intvalue += value.intvalue;
v2.valueKind = value.valueKind;
return v2;
}
return v; return v;
} }

View File

@ -2286,6 +2286,7 @@ struct ValueFlowAnalyzer : Analyzer {
return v.isSymbolicValue() && currValue->equalValue(v); return v.isSymbolicValue() && currValue->equalValue(v);
})) }))
return false; return false;
const bool isPoint = currValue->bound == ValueFlow::Value::Bound::Point && currValue->isIntValue();
const bool exact = !currValue->isIntValue() || currValue->isImpossible(); const bool exact = !currValue->isIntValue() || currValue->isImpossible();
for (const ValueFlow::Value& v : tok->values()) { for (const ValueFlow::Value& v : tok->values()) {
if (!v.isSymbolicValue()) if (!v.isSymbolicValue())
@ -2295,7 +2296,7 @@ struct ValueFlowAnalyzer : Analyzer {
const bool toImpossible = v.isImpossible() && currValue->isKnown(); const bool toImpossible = v.isImpossible() && currValue->isKnown();
if (!v.isKnown() && !toImpossible) if (!v.isKnown() && !toImpossible)
continue; continue;
if (exact && v.intvalue != 0) if (exact && v.intvalue != 0 && !isPoint)
continue; continue;
std::vector<MathLib::bigint> r; std::vector<MathLib::bigint> r;
ValueFlow::Value::Bound bound = currValue->bound; ValueFlow::Value::Bound bound = currValue->bound;

View File

@ -7143,6 +7143,17 @@ private:
" return 1 / x;\n" " return 1 / x;\n"
"}\n"; "}\n";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
code = "void f(int k) {\n"
" int x = k;\n"
" int j = k;\n"
" x--;\n"
" if (k != 0) {\n"
" x;\n"
" }\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 6U, -1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 6U, -1));
} }
void valueFlowSymbolicIdentity() void valueFlowSymbolicIdentity()