Skip to content

Commit

Permalink
test/refactor: upgrade to cppcheck 2.9 and fix warnings (#5049)
Browse files Browse the repository at this point in the history
* refactor: resolve warnings thrown by cppcheck 2.9

* test: upgrade cppcheck to version 2.9
  • Loading branch information
PastaPastaPasta committed Oct 18, 2022
1 parent 0a61b95 commit ad88fab
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion contrib/containers/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion src/bls/bls_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ struct ContributionVerifier : public std::enable_shared_from_this<ContributionVe
size_t batchIdx = 0;
std::vector<bool> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cxxtimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Timer {
* 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.
Expand Down
2 changes: 1 addition & 1 deletion src/evo/cbtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/evo/specialtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inline bool GetTxPayload(const std::vector<unsigned char>& 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();
Expand Down
2 changes: 1 addition & 1 deletion src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ std::set<uint256> 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 */
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
40 changes: 20 additions & 20 deletions src/llmq/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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 << " ]";
Expand All @@ -172,23 +172,23 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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 << "]";
Expand Down Expand Up @@ -263,11 +263,11 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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]) {
Expand All @@ -276,11 +276,11 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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]) {
Expand All @@ -289,11 +289,11 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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) {
}
}
}
Expand All @@ -303,7 +303,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> BuildNewQuorumQuarterMembers(cons
if (!dmn->pdmnState->IsBanned()) {
try {
MnsNotUsedAtH.AddMN(dmn);
} catch (std::runtime_error &e) {
} catch (const std::runtime_error& e) {
}
}
}
Expand All @@ -319,7 +319,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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 << "]";
Expand Down Expand Up @@ -410,7 +410,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> 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 << "]";
Expand Down Expand Up @@ -500,13 +500,13 @@ std::pair<CDeterministicMNList, CDeterministicMNList> 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) {
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/masternode/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CMasternodeMetaMan
{
LOCK(cs);
std::vector<CMasternodeMetaInfo> tmpMetaInfo;
for (auto& p : metaInfos) {
for (const auto& p : metaInfos) {
tmpMetaInfo.emplace_back(*p.second);
}
s << SERIALIZATION_VERSION_STRING << tmpMetaInfo << nDsqCount;
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
8 changes: 4 additions & 4 deletions src/rpc/rpcquorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/statsd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ad88fab

Please sign in to comment.