From e32ccb591b4bb8782bb47b96077eab0beb351717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Sep 2020 08:29:05 +0200 Subject: [PATCH] Fixed clarifyCalculation fp for 'a % b ? "a" : "b"'. seen in daca@home. --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2485ecdca..e042b3729 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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 diff --git a/test/testother.cpp b/test/testother.cpp index 963703eef..f696b792b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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());