From b80d06b69efc092bdfab04a354d5235ee8c88f3c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 7 Jun 2022 21:13:31 +0200 Subject: [PATCH] Don't warn for 'x | MACRO' when MACRO is 0 (#4176) --- lib/checkcondition.cpp | 8 ++++---- test/testcondition.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 85e60ac18..4c3597396 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -311,11 +311,11 @@ void CheckCondition::checkBadBitmaskCheck() if (isBoolean && isTrue) badBitmaskCheckError(tok); - const bool isNoOp = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->values().front().intvalue == 0) || - (tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->values().front().intvalue == 0); + const bool isZero1 = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->values().front().intvalue == 0); + const bool isZero2 = (tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->values().front().intvalue == 0); - if (isNoOp && !tok->isExpandedMacro()) - badBitmaskCheckError(tok, isNoOp); + if ((isZero1 || isZero2) && !tok->isExpandedMacro() && !(isZero1 && tok->astOperand1()->isExpandedMacro()) && !(isZero2 && tok->astOperand2()->isExpandedMacro())) + badBitmaskCheckError(tok, /*isNoOp*/ true); } } } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 0af7221d7..c73a04040 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -899,6 +899,12 @@ private: " return EIGHTTOIS(0);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("#define O_RDONLY 0\n" + "void f(const char* s, int* pFd) {\n" + " *pFd = open(s, O_RDONLY | O_BINARY, 0);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }