From 69846b2a06fc476fd1b6a52b9454dea81e2350e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 8 Jun 2012 17:24:54 +0200 Subject: [PATCH] Fixed #3872 ('char variables in bit operations' warning) --- lib/checkother.cpp | 2 +- test/testcharvar.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5a03986b6..63a728fe8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1794,7 +1794,7 @@ void CheckOther::checkCharVariable() else if (Token::Match(tok, "[;{}] %var% = %any% [&^|] ( * %var% ) ;")) { const Variable* var = symbolDatabase->getVariableFromVarId(tok->tokAt(7)->varId()); - if (!var || !var->isPointer()) + if (!var || !var->isPointer() || !Token::Match(var->typeStartToken(), "static| const| char")) continue; // it's ok with a bitwise and where the other operand is 0xff or less.. if (tok->strAt(4) == "&" && tok->tokAt(3)->isNumber() && MathLib::isGreater("0x100", tok->strAt(3))) diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index 245a475c4..4a6c0623f 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -204,6 +204,14 @@ private: " return ret;\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #3872 - false positive + check("int f(int *p) {\n" + " int ret = a();\n" + " ret |= *p;\n" + " return ret;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };