Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2006,9 +2006,7 @@ bool isOppositeExpression(const Token * const tok1, const Token * const tok2, co
static bool functionModifiesArguments(const Function* f)
{
return std::any_of(f->argumentList.cbegin(), f->argumentList.cend(), [](const Variable& var) {
if (var.isReference() || var.isPointer())
return !var.isConst();
return true;
return var.isReference() && !var.isConst();
});
}

Expand Down Expand Up @@ -2089,7 +2087,7 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
return false;
});
}
return true;
return false;
}

bool isConstExpression(const Token *tok, const Library& library)
Expand Down
2 changes: 1 addition & 1 deletion lib/checksizeof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void CheckSizeof::checkSizeofForPointerSize()
variable = tok;
else if (tok->strAt(1) == ")" && Token::Match(tok->linkAt(1)->tokAt(-2), "%var% ="))
variable = tok->linkAt(1)->tokAt(-2);
else if (tok->link() && Token::Match(tok, "> ( %name% (") && mSettings->library.getAllocFuncInfo(tok->tokAt(2)) && Token::Match(tok->link()->tokAt(-3), "%var% ="))
else if (tok->link() && Token::Match(tok, "> ( %name% (") && Token::Match(tok->link()->tokAt(-3), "%var% ="))
variable = tok->link()->tokAt(-3);
tokSize = tok->tokAt(4);
tokFunc = tok->tokAt(2);
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5895,7 +5895,7 @@
callarg->typeStartToken()->isLong() == funcarg->typeStartToken()->isLong()) {
same++;
} else if (callarg->isArrayOrPointer()) {
if (ptrequals && constEquals && funcarg->typeStartToken()->str() == "void")
if (ptrequals && constEquals && funcarg->typeStartToken()->str() == "void") // cppcheck-suppress knownConditionTrueFalse (#14418)
Comment thread Fixed
fallback1++;
else if (constEquals && funcarg->isStlStringType() && Token::Match(callarg->typeStartToken(), "char|wchar_t"))
fallback2++;
Expand Down
13 changes: 13 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class TestCondition : public TestFixture {
TEST_CASE(alwaysTrueContainer);
TEST_CASE(alwaysTrueLoop);
TEST_CASE(alwaysTrueTryCatch);
TEST_CASE(alwaysTrueSideEffect);
TEST_CASE(multiConditionAlwaysTrue);
TEST_CASE(duplicateCondition);

Expand Down Expand Up @@ -5590,6 +5591,18 @@ class TestCondition : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueSideEffect() {
check("bool check(const char* const);\n" // #14416
"void create(const char*);\n"
"void f(const char* n) {\n"
" if (!check(n)) {\n"
" create(n);\n"
" if (check(n)) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void multiConditionAlwaysTrue() {
check("void f() {\n"
" int val = 0;\n"
Expand Down
Loading