From ad88fab80dd6da08a03eeb52271a4a5b983aa4e0 Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Tue, 18 Oct 2022 05:24:00 -0500 Subject: [PATCH] test/refactor: upgrade to cppcheck 2.9 and fix warnings (#5049) * refactor: resolve warnings thrown by cppcheck 2.9 * test: upgrade cppcheck to version 2.9 --- contrib/containers/ci/Dockerfile | 2 +- src/bls/bls_worker.cpp | 2 +- src/cxxtimer.hpp | 2 +- src/evo/cbtx.cpp | 2 +- src/evo/specialtx.h | 2 +- src/governance/object.cpp | 2 +- src/llmq/quorums.cpp | 2 +- src/llmq/utils.cpp | 40 ++++++++++++++++---------------- src/masternode/meta.h | 2 +- src/rpc/coinjoin.cpp | 2 +- src/rpc/rpcquorums.cpp | 8 +++---- src/statsd_client.h | 2 +- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/contrib/containers/ci/Dockerfile b/contrib/containers/ci/Dockerfile index 23bacefc47..1f6f872818 100644 --- a/contrib/containers/ci/Dockerfile +++ b/contrib/containers/ci/Dockerfile @@ -79,7 +79,7 @@ RUN apt-get update && apt-get install $APT_ARGS \ xorriso \ && rm -rf /var/lib/apt/lists/* -ARG CPPCHECK_VERSION=2.8 +ARG CPPCHECK_VERSION=2.9 RUN curl -sL "https://github.com/danmar/cppcheck/archive/${CPPCHECK_VERSION}.tar.gz" | tar -xvzf - --directory /tmp/ RUN cd /tmp/cppcheck-${CPPCHECK_VERSION} && mkdir build && cd build && cmake .. && cmake --build . -j 8 ENV PATH "/tmp/cppcheck-${CPPCHECK_VERSION}/build/bin:${PATH}" diff --git a/src/bls/bls_worker.cpp b/src/bls/bls_worker.cpp index ccf93d715c..800512a1f1 100644 --- a/src/bls/bls_worker.cpp +++ b/src/bls/bls_worker.cpp @@ -478,7 +478,7 @@ struct ContributionVerifier : public std::enable_shared_from_this result(vvecs.size()); for (size_t i = 0; i < vvecs.size(); i += batchSize) { - auto& batchState = batchStates[batchIdx++]; + const auto& batchState = batchStates[batchIdx++]; for (size_t j = 0; j < batchState.count; j++) { result[batchState.start + j] = batchState.verifyResults[j] != 0; } diff --git a/src/cxxtimer.hpp b/src/cxxtimer.hpp index c3f0b72222..155c5051ff 100644 --- a/src/cxxtimer.hpp +++ b/src/cxxtimer.hpp @@ -46,7 +46,7 @@ public: * If true, the timer is started just after construction. * Otherwise, it will not be automatically started. */ - Timer(bool start = false); + explicit Timer(bool start = false); /** * Copy constructor. diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index b32d71554a..444a81cbf8 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -241,7 +241,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre // now add the commitments from the current block, which are not returned by GetMinedAndActiveCommitmentsUntilBlock // due to the use of pindexPrev (we don't have the tip index here) for (size_t i = 1; i < block.vtx.size(); i++) { - auto& tx = block.vtx[i]; + const auto& tx = block.vtx[i]; if (tx->nVersion == 3 && tx->nType == TRANSACTION_QUORUM_COMMITMENT) { llmq::CFinalCommitmentTxPayload qc; diff --git a/src/evo/specialtx.h b/src/evo/specialtx.h index 86dbee44ff..f7ea847848 100644 --- a/src/evo/specialtx.h +++ b/src/evo/specialtx.h @@ -19,7 +19,7 @@ inline bool GetTxPayload(const std::vector& payload, T& obj) CDataStream ds(payload, SER_NETWORK, PROTOCOL_VERSION); try { ds >> obj; - } catch (std::exception& e) { + } catch (const std::exception& e) { return false; } return ds.empty(); diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 3d1ad65571..488d4beb27 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -264,7 +264,7 @@ std::set CGovernanceObject::RemoveInvalidVotes(const COutPoint& mnOutpo } std::string removedStr; - for (auto& h : removedVotes) { + for (const auto& h : removedVotes) { removedStr += strprintf(" %s\n", h.ToString()); } LogPrintf("CGovernanceObject::%s -- Removed %d invalid votes for %s from MN %s:\n%s", __func__, removedVotes.size(), nParentHash.ToString(), mnOutpoint.ToString(), removedStr); /* Continued */ diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 70ff54cd8f..b1ac354d95 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -272,7 +272,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial return; } - for (auto& params : Params().GetConsensus().llmqs) { + for (const auto& params : Params().GetConsensus().llmqs) { CheckQuorumConnections(params, pindexNew); } diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 49456c9b8d..43d2c1c2ad 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -150,19 +150,19 @@ std::vector> ComputeQuorumMembersByQuarterRota std::stringstream ss; ss << " 3Cmns["; - for (auto &m: previousQuarters.quarterHMinus3C[i]) { + for (const auto &m: previousQuarters.quarterHMinus3C[i]) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << " ] 2Cmns["; - for (auto &m: previousQuarters.quarterHMinus2C[i]) { + for (const auto &m: previousQuarters.quarterHMinus2C[i]) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << " ] Cmns["; - for (auto &m: previousQuarters.quarterHMinusC[i]) { + for (const auto &m: previousQuarters.quarterHMinusC[i]) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << " ] new["; - for (auto &m: newQuarterMembers[i]) { + for (const auto &m: newQuarterMembers[i]) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << " ]"; @@ -172,23 +172,23 @@ std::vector> ComputeQuorumMembersByQuarterRota } for (auto i = 0; i < nQuorums; ++i) { - for (auto &m: previousQuarters.quarterHMinus3C[i]) { + for (const auto &m: previousQuarters.quarterHMinus3C[i]) { quorumMembers[i].push_back(std::move(m)); } - for (auto &m: previousQuarters.quarterHMinus2C[i]) { + for (const auto &m: previousQuarters.quarterHMinus2C[i]) { quorumMembers[i].push_back(std::move(m)); } - for (auto &m: previousQuarters.quarterHMinusC[i]) { + for (const auto &m: previousQuarters.quarterHMinusC[i]) { quorumMembers[i].push_back(std::move(m)); } - for (auto &m: newQuarterMembers[i]) { + for (const auto &m: newQuarterMembers[i]) { quorumMembers[i].push_back(std::move(m)); } if (LogAcceptCategory(BCLog::LLMQ)) { std::stringstream ss; ss << " ["; - for (auto &m: quorumMembers[i]) { + for (const auto &m: quorumMembers[i]) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << "]"; @@ -263,11 +263,11 @@ std::vector> BuildNewQuorumQuarterMembers(cons } try { MnsUsedAtH.AddMN(mn); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { } try { MnsUsedAtHIndexed[i].AddMN(mn); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { } } for (const auto& mn : previousQuarters.quarterHMinus2C[i]) { @@ -276,11 +276,11 @@ std::vector> BuildNewQuorumQuarterMembers(cons } try { MnsUsedAtH.AddMN(mn); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { } try { MnsUsedAtHIndexed[i].AddMN(mn); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { } } for (const auto& mn : previousQuarters.quarterHMinus3C[i]) { @@ -289,11 +289,11 @@ std::vector> BuildNewQuorumQuarterMembers(cons } try { MnsUsedAtH.AddMN(mn); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { } try { MnsUsedAtHIndexed[i].AddMN(mn); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { } } } @@ -303,7 +303,7 @@ std::vector> BuildNewQuorumQuarterMembers(cons if (!dmn->pdmnState->IsBanned()) { try { MnsNotUsedAtH.AddMN(dmn); - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { } } } @@ -319,7 +319,7 @@ std::vector> BuildNewQuorumQuarterMembers(cons if (LogAcceptCategory(BCLog::LLMQ)) { std::stringstream ss; ss << " ["; - for (auto &m: sortedCombinedMnsList) { + for (const auto &m: sortedCombinedMnsList) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << "]"; @@ -410,7 +410,7 @@ std::vector> GetQuorumQuarterMembersBySnapshot if (LogAcceptCategory(BCLog::LLMQ)) { std::stringstream ss; ss << " ["; - for (auto &m: sortedCombinedMns) { + for (const auto &m: sortedCombinedMns) { ss << m->proTxHash.ToString().substr(0, 4) << "|"; } ss << "]"; @@ -500,13 +500,13 @@ std::pair GetMNUsageBySnapshot(Conse if (snapshot.activeQuorumMembers[i]) { try { usedMNs.AddMN(dmn); - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { } } else { if (!dmn->pdmnState->IsBanned()) { try { nonUsedMNs.AddMN(dmn); - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { } } } diff --git a/src/masternode/meta.h b/src/masternode/meta.h index f41e695f5a..662456fced 100644 --- a/src/masternode/meta.h +++ b/src/masternode/meta.h @@ -108,7 +108,7 @@ public: { LOCK(cs); std::vector tmpMetaInfo; - for (auto& p : metaInfos) { + for (const auto& p : metaInfos) { tmpMetaInfo.emplace_back(*p.second); } s << SERIALIZATION_VERSION_STRING << tmpMetaInfo << nDsqCount; diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index 5db9854d4f..69680e6bd5 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -63,7 +63,7 @@ static UniValue coinjoin(const JSONRPCRequest& request) throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing has been started already."); } - NodeContext& node = EnsureNodeContext(request.context); + const NodeContext& node = EnsureNodeContext(request.context); bool result = it->second->DoAutomaticDenominating(*node.connman); return "Mixing " + (result ? "started successfully" : ("start failed: " + it->second->GetStatuses().original + ", will retry")); } diff --git a/src/rpc/rpcquorums.cpp b/src/rpc/rpcquorums.cpp index 8046a56a55..40834f784d 100644 --- a/src/rpc/rpcquorums.cpp +++ b/src/rpc/rpcquorums.cpp @@ -65,12 +65,12 @@ static UniValue quorum_list(const JSONRPCRequest& request) CBlockIndex* pindexTip = WITH_LOCK(cs_main, return ::ChainActive().Tip()); - for (auto& type : llmq::utils::GetEnabledQuorumTypes(pindexTip)) { + for (const auto& type : llmq::utils::GetEnabledQuorumTypes(pindexTip)) { const auto& llmq_params = llmq::GetLLMQParams(type); UniValue v(UniValue::VARR); auto quorums = llmq::quorumManager->ScanQuorums(type, pindexTip, count > -1 ? count : llmq_params.signingActiveQuorumCount); - for (auto& q : quorums) { + for (const auto& q : quorums) { v.push_back(q->qc->quorumHash.ToString()); } @@ -108,7 +108,7 @@ static UniValue BuildQuorumInfo(const llmq::CQuorumCPtr& quorum, bool includeMem if (includeMembers) { UniValue membersArr(UniValue::VARR); for (size_t i = 0; i < quorum->members.size(); i++) { - auto& dmn = quorum->members[i]; + const auto& dmn = quorum->members[i]; UniValue mo(UniValue::VOBJ); mo.pushKV("proTxHash", dmn->proTxHash.ToString()); mo.pushKV("service", dmn->pdmnState->addr.ToString()); @@ -227,7 +227,7 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request) } }); UniValue arr(UniValue::VARR); - for (auto& ec : allConnections) { + for (const auto& ec : allConnections) { UniValue ecj(UniValue::VOBJ); ecj.pushKV("proTxHash", ec.ToString()); if (foundConnections.count(ec)) { diff --git a/src/statsd_client.h b/src/statsd_client.h index c5f5f58c09..b222918eb3 100644 --- a/src/statsd_client.h +++ b/src/statsd_client.h @@ -21,7 +21,7 @@ struct _StatsdClientData; class StatsdClient { public: - StatsdClient(const std::string& host = DEFAULT_STATSD_HOST, int port = DEFAULT_STATSD_PORT, const std::string& ns = DEFAULT_STATSD_NAMESPACE); + explicit StatsdClient(const std::string& host = DEFAULT_STATSD_HOST, int port = DEFAULT_STATSD_PORT, const std::string& ns = DEFAULT_STATSD_NAMESPACE); ~StatsdClient(); public: