diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 1432c776a..4d4921bca 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -95,7 +95,11 @@ void CheckFunctions::invalidFunctionUsage() const Token *top = argtok; while (top->astParent() && top->astParent()->str() != "," && top->astParent() != tok->next()) 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)) invalidFunctionArgBoolError(top, functionToken->str(), argnr); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 67659d6cb..ed7aa7967 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -404,6 +404,15 @@ private: 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()); + 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) check("void record(char* buf, int n) {\n" " memset(buf, 0, n < 255);\n" /* KO */