Fixed #3878 (Sign extension with unsigned char false positive)
This commit is contained in:
parent
b9e35b8516
commit
905615e991
|
@ -1794,7 +1794,7 @@ void CheckOther::checkCharVariable()
|
||||||
|
|
||||||
else if (Token::Match(tok, "[;{}] %var% = %any% [&^|] ( * %var% ) ;")) {
|
else if (Token::Match(tok, "[;{}] %var% = %any% [&^|] ( * %var% ) ;")) {
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(tok->tokAt(7)->varId());
|
const Variable* var = symbolDatabase->getVariableFromVarId(tok->tokAt(7)->varId());
|
||||||
if (!var || !var->isPointer() || var->typeStartToken()->str() != "char")
|
if (!var || !var->isPointer() || var->typeStartToken()->str() != "char" || var->typeStartToken()->isUnsigned())
|
||||||
continue;
|
continue;
|
||||||
// it's ok with a bitwise and where the other operand is 0xff or less..
|
// 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)))
|
if (tok->strAt(4) == "&" && tok->tokAt(3)->isNumber() && MathLib::isGreater("0x100", tok->strAt(3)))
|
||||||
|
|
|
@ -212,6 +212,14 @@ private:
|
||||||
" return ret;\n"
|
" return ret;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #3878 - false positive
|
||||||
|
check("int f(unsigned char *p) {\n"
|
||||||
|
" int ret = a();\n"
|
||||||
|
" ret |= *p;\n"
|
||||||
|
" return ret;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue