Fixed clarifyCalculation fp for 'a % b ? "a" : "b"'. seen in daca@home.

This commit is contained in:
Daniel Marjamäki 2020-09-29 08:29:05 +02:00
parent 4e4108dc8b
commit e32ccb591b
2 changed files with 5 additions and 2 deletions

View File

@ -160,8 +160,8 @@ void CheckOther::clarifyCalculation()
if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->tokType() != Token::eBitOp)
continue;
// bit operation in lhs and pointer in rhs => no clarification is needed
if (tok->astOperand1()->tokType() == Token::eBitOp && tok->astOperand2()->valueType() && tok->astOperand2()->valueType()->pointer > 0)
// non-pointer calculation in lhs and pointer in rhs => no clarification is needed
if (tok->astOperand1()->isBinaryOp() && Token::Match(tok->astOperand1(), "%or%|&|%|*|/") && tok->astOperand2()->valueType() && tok->astOperand2()->valueType()->pointer > 0)
continue;
// bit operation in lhs and char literals in rhs => probably no mistake

View File

@ -4272,6 +4272,9 @@ private:
check("void f(int x) { const char *p = x & 1 ? \"1\" : \"0\"; }");
ASSERT_EQUALS("", errout.str());
check("void foo() { x = a % b ? \"1\" : \"0\"; }");
ASSERT_EQUALS("", errout.str());
check("void f(int x) { return x & 1 ? '1' : '0'; }");
ASSERT_EQUALS("", errout.str());