Skip to content

Commit 69846b2

Browse files
committed
Fixed danmar#3872 ('char variables in bit operations' warning)
1 parent c5da030 commit 69846b2

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ void CheckOther::checkCharVariable()
17941794

17951795
else if (Token::Match(tok, "[;{}] %var% = %any% [&^|] ( * %var% ) ;")) {
17961796
const Variable* var = symbolDatabase->getVariableFromVarId(tok->tokAt(7)->varId());
1797-
if (!var || !var->isPointer())
1797+
if (!var || !var->isPointer() || !Token::Match(var->typeStartToken(), "static| const| char"))
17981798
continue;
17991799
// it's ok with a bitwise and where the other operand is 0xff or less..
18001800
if (tok->strAt(4) == "&" && tok->tokAt(3)->isNumber() && MathLib::isGreater("0x100", tok->strAt(3)))

test/testcharvar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ class TestCharVar : public TestFixture {
204204
" return ret;\n"
205205
"}");
206206
ASSERT_EQUALS("", errout.str());
207+
208+
// #3872 - false positive
209+
check("int f(int *p) {\n"
210+
" int ret = a();\n"
211+
" ret |= *p;\n"
212+
" return ret;\n"
213+
"}");
214+
ASSERT_EQUALS("", errout.str());
207215
}
208216
};
209217

0 commit comments

Comments
 (0)