Fix issue 10049: False positive: generic reverse valueflow analysis (#2959)

This commit is contained in:
Paul Fultz II 2020-12-19 01:28:58 -06:00 committed by GitHub
parent ad7a53e88c
commit 2541b6034f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -160,7 +160,7 @@ struct ReverseTraversal {
settings); settings);
} }
// Assignment to // Assignment to
} else if (lhsAction.matches()) { } else if (lhsAction.matches() && !assignTok->astOperand2()->hasKnownValue()) {
const std::string info = "Assignment to '" + assignTok->expressionString() + "'"; const std::string info = "Assignment to '" + assignTok->expressionString() + "'";
ValuePtr<Analyzer> a = analyzer->reanalyze(assignTok->astOperand2(), info); ValuePtr<Analyzer> a = analyzer->reanalyze(assignTok->astOperand2(), info);
if (a) { if (a) {

View File

@ -710,6 +710,18 @@ private:
" return 1/a->x;\n" " return 1/a->x;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #10049
check("int f(int argc) {\n"
" int quotient, remainder;\n"
" remainder = argc % 2;\n"
" argc = 2;\n"
" quotient = argc;\n"
" if (quotient != 0) \n"
" return quotient;\n"
" return remainder;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void nanInArithmeticExpression() { void nanInArithmeticExpression() {