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