Fixed #6990 (false negative: Invalid abs() argument nr 1. A non-boolean value is required.)

This commit is contained in:
Daniel Marjamäki 2015-12-26 01:38:41 +01:00
parent 64494ca226
commit 293bd2eead
2 changed files with 14 additions and 1 deletions

View File

@ -95,7 +95,11 @@ void CheckFunctions::invalidFunctionUsage()
const Token *top = argtok; const Token *top = argtok;
while (top->astParent() && top->astParent()->str() != "," && top->astParent() != tok->next()) while (top->astParent() && top->astParent()->str() != "," && top->astParent() != tok->next())
top = top->astParent(); top = top->astParent();
if (top->isComparisonOp() || Token::Match(top, "%oror%|&&")) { const Token *var = top;
while (Token::Match(top, ".|::"))
var = var->astOperand2();
if (Token::Match(top, "%comp%|%oror%|&&|!|true|false") ||
(var && var->variable() && Token::Match(var->variable()->typeStartToken(), "bool"))) {
if (_settings->library.isboolargbad(functionToken, argnr)) if (_settings->library.isboolargbad(functionToken, argnr))
invalidFunctionArgBoolError(top, functionToken->str(), argnr); invalidFunctionArgBoolError(top, functionToken->str(), argnr);

View File

@ -404,6 +404,15 @@ private:
check("int f() { memset(a,b,sizeof(a)!=0); }"); check("int f() { memset(a,b,sizeof(a)!=0); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
check("int f() { memset(a,b,!c); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
// Ticket #6990
check("int f(bool c) { memset(a,b,c); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
check("int f() { memset(a,b,true); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
// Ticket #6588 (c mode) // Ticket #6588 (c mode)
check("void record(char* buf, int n) {\n" check("void record(char* buf, int n) {\n"
" memset(buf, 0, n < 255);\n" /* KO */ " memset(buf, 0, n < 255);\n" /* KO */