Fixed #4925 (False positive: checkother style)

When using a variable that is assigned a function pointer checks for
pointers are triggered which would complain if used in arithmetic
comparisions (eventhough it will be valid code if the function returns
an int)
This commit is contained in:
Carlo Marcelo Arenas Belon 2013-07-23 08:19:20 -07:00 committed by Daniel Marjamki
parent 8aa99e8c54
commit aa0560fe3b
2 changed files with 17 additions and 1 deletions

View File

@ -3217,7 +3217,7 @@ void CheckOther::checkSignOfUnsignedVariable()
const Variable *var = tok->tokAt(2)->variable();
if (var && var->typeEndToken()->isUnsigned())
unsignedLessThanZeroError(tok, var->name(), inconclusive);
else if (var && var->isPointer() && !Token::Match(tok->tokAt(3), "[.[]"))
else if (var && var->isPointer() && !Token::Match(tok->tokAt(3), "[.[(]"))
pointerLessThanZeroError(tok, inconclusive);
} else if (Token::Match(tok, "0 <= %var%") && tok->tokAt(2)->varId() && !Token::Match(tok->tokAt(3), "+|-|*|/") && !Token::Match(tok->previous(), "+|-|<<|>>|~")) {
const Variable *var = tok->tokAt(2)->variable();

View File

@ -4949,6 +4949,22 @@ private:
" bar();\n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"void foo() {\n"
" int (*t)(void *a, void *b);\n"
" if (t(a, b) < 0)\n"
" bar();\n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"void foo() {\n"
" int (*t)(void *a, void *b);\n"
" if (0 > t(a, b))\n"
" bar();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void checkForSuspiciousSemicolon1() {