File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff 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 () || var->typeStartToken ()->str () != " char" )
1797+ if (!var || !var->isPointer () || var->typeStartToken ()->str () != " char" || var-> typeStartToken ()-> isUnsigned () )
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 )))
Original file line number Diff line number Diff line change @@ -212,6 +212,14 @@ class TestCharVar : public TestFixture {
212212 " return ret;\n "
213213 " }" );
214214 ASSERT_EQUALS (" " , errout.str ());
215+
216+ // #3878 - false positive
217+ check (" int f(unsigned char *p) {\n "
218+ " int ret = a();\n "
219+ " ret |= *p;\n "
220+ " return ret;\n "
221+ " }" );
222+ ASSERT_EQUALS (" " , errout.str ());
215223 }
216224};
217225
You can’t perform that action at this time.
0 commit comments