From 2541b6034f382c8a3ad8f546223c27757e884fef Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 19 Dec 2020 01:28:58 -0600 Subject: [PATCH] Fix issue 10049: False positive: generic reverse valueflow analysis (#2959) --- lib/reverseanalyzer.cpp | 2 +- test/testother.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp index 31deda58d..43da453b2 100644 --- a/lib/reverseanalyzer.cpp +++ b/lib/reverseanalyzer.cpp @@ -160,7 +160,7 @@ struct ReverseTraversal { settings); } // Assignment to - } else if (lhsAction.matches()) { + } else if (lhsAction.matches() && !assignTok->astOperand2()->hasKnownValue()) { const std::string info = "Assignment to '" + assignTok->expressionString() + "'"; ValuePtr a = analyzer->reanalyze(assignTok->astOperand2(), info); if (a) { diff --git a/test/testother.cpp b/test/testother.cpp index 93b589694..16b365d6c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -710,6 +710,18 @@ private: " return 1/a->x;\n" "}\n"); 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() {