From 5856fef83b2c5480843732243ab2c3ce8dc991b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 25 Sep 2020 20:27:16 +0200 Subject: [PATCH] Fixed #9914 (False positive: knownArgument for 'x && false') --- lib/checkother.cpp | 6 ++++++ test/testother.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 762673125..3103bfee3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3144,6 +3144,12 @@ void CheckOther::checkKnownArgument() } if (Token::simpleMatch(child->previous(), "sizeof (")) return ChildrenToVisit::none; + if (Token::simpleMatch(child, "*") && (Token::simpleMatch(child->astOperand1(), "0") || Token::simpleMatch(child->astOperand2(), "0"))) + return ChildrenToVisit::none; + if (Token::simpleMatch(child, "&&") && (Token::simpleMatch(child->astOperand1(), "false") || Token::simpleMatch(child->astOperand2(), "false"))) + return ChildrenToVisit::none; + if (Token::simpleMatch(child, "||") && (Token::simpleMatch(child->astOperand1(), "true") || Token::simpleMatch(child->astOperand2(), "true"))) + return ChildrenToVisit::none; return ChildrenToVisit::op1_and_op2; }); if (varexpr.empty()) diff --git a/test/testother.cpp b/test/testother.cpp index 66740a98e..40833c093 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8900,6 +8900,17 @@ private: " dostuff(self->maxsize * sizeof(intptr_t));\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #9914 - zeroed expression + check("void f(int x) {\n" + " dostuff(x && false);\n" + " dostuff(false && x);\n" + " dostuff(x || true);\n" + " dostuff(true || x);\n" + " dostuff(x * 0);\n" + " dostuff(0 * x);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void checkComparePointers() {