Skip to content

Commit 293bd2e

Browse files
committed
Fixed danmar#6990 (false negative: Invalid abs() argument nr 1. A non-boolean value is required.)
1 parent 64494ca commit 293bd2e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/checkfunctions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ void CheckFunctions::invalidFunctionUsage()
9595
const Token *top = argtok;
9696
while (top->astParent() && top->astParent()->str() != "," && top->astParent() != tok->next())
9797
top = top->astParent();
98-
if (top->isComparisonOp() || Token::Match(top, "%oror%|&&")) {
98+
const Token *var = top;
99+
while (Token::Match(top, ".|::"))
100+
var = var->astOperand2();
101+
if (Token::Match(top, "%comp%|%oror%|&&|!|true|false") ||
102+
(var && var->variable() && Token::Match(var->variable()->typeStartToken(), "bool"))) {
99103
if (_settings->library.isboolargbad(functionToken, argnr))
100104
invalidFunctionArgBoolError(top, functionToken->str(), argnr);
101105

test/testfunctions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,15 @@ class TestFunctions : public TestFixture {
404404
check("int f() { memset(a,b,sizeof(a)!=0); }");
405405
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
406406

407+
check("int f() { memset(a,b,!c); }");
408+
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
409+
410+
// Ticket #6990
411+
check("int f(bool c) { memset(a,b,c); }");
412+
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
413+
check("int f() { memset(a,b,true); }");
414+
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str());
415+
407416
// Ticket #6588 (c mode)
408417
check("void record(char* buf, int n) {\n"
409418
" memset(buf, 0, n < 255);\n" /* KO */

0 commit comments

Comments
 (0)