From c23c25d00bd59965785a7fd7d2f716ac825475b2 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 23 Feb 2024 16:42:26 +0700 Subject: [PATCH] test: supress any_of suggestions in cppcheck-dash even it maybe useful lint message for some particular case, sometimes it asks to make an refactoring that will be over-complex. For example, it asks to refactor external loop to std::any_of: ``` for (const auto& inner_entry : vecEntries) { if (ranges::any_of(inner_entry.vecTxDSIn, [&txin](const auto& txdsin){ return txdsin.prevout == txin.prevout; })) { LogPrint(BCLog::COINJOIN, "CCoinJoinServer::%s -- ERROR: already have this txin in entries\n", __func__); nMessageIDRet = ERR_ALREADY_HAVE; // Two peers sent the same input? Can't really say who is the malicious one here, // could be that someone is picking someone else's inputs randomly trying to force // collateral consumption. Do not punish. return false; } } ``` That's possible to refactor, but that's unreasonable complexity to have an lambda inside an lambda... That's unreasonable. Some other suggestion are also non-trivial. One more suppression for any_of in llmq/commitment which is false-alarm: There's used index but linter doesn't see it: ``` for (const auto i : irange::range(members.size(), size_t(llmq_params.size))) { if (validMembers[i]) { LogPrintfFinalCommitment("q[%s] invalid validMembers bitset. bit %d should not be set\n", quorumHash.ToString(), i); return false; } if (signers[i]) { LogPrintfFinalCommitment("q[%s] invalid signers bitset. bit %d should not be set\n", quorumHash.ToString(), i); return false; } } ``` --- test/lint/lint-cppcheck-dash.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/lint/lint-cppcheck-dash.sh b/test/lint/lint-cppcheck-dash.sh index f677e1f5a7..185ad8aef8 100755 --- a/test/lint/lint-cppcheck-dash.sh +++ b/test/lint/lint-cppcheck-dash.sh @@ -30,6 +30,8 @@ IGNORED_WARNINGS=( "src/rpc/masternode.cpp:.*:21: warning: Consider using std::copy algorithm instead of a raw loop." # UniValue doesn't support std::copy "src/cachemultimap.h:.*: warning: Variable 'mapIt' can be declared as reference to const" "src/evo/simplifiedmns.cpp:.*:20: warning: Consider using std::copy algorithm instead of a raw loop." + "src/llmq/commitment.cpp.* warning: Consider using std::all_of or std::none_of algorithm instead of a raw loop. \[useStlAlgorithm\]" + # General catchall, for some reason any value named 'hash' is viewed as never used. "Variable 'hash' is assigned a value that is never used." @@ -37,7 +39,8 @@ IGNORED_WARNINGS=( # "Consider performing initialization in initialization list." "Consider using std::transform algorithm instead of a raw loop." "Consider using std::accumulate algorithm instead of a raw loop." -# "Consider using std::any_of algorithm instead of a raw loop." + "Consider using std::any_of algorithm instead of a raw loop." + "Consider using std::copy_if algorithm instead of a raw loop." # "Consider using std::count_if algorithm instead of a raw loop." # "Consider using std::find_if algorithm instead of a raw loop." # "Member variable '.*' is not initialized in the constructor."