Fixed #3872 ('char variables in bit operations' warning)

This commit is contained in:
Daniel Marjamäki 2012-06-08 17:24:54 +02:00
parent c5da030674
commit 69846b2a06
2 changed files with 9 additions and 1 deletions

View File

@ -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)))

View File

@ -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());
}
};