dash/test/lint/lint-cppcheck-dash.sh

102 lines
4.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
#
# Copyright (c) 2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
export LC_ALL=C
ENABLED_CHECKS=(
"Class '.*' has a constructor with 1 argument that is not explicit."
"Struct '.*' has a constructor with 1 argument that is not explicit."
"Function parameter '.*' should be passed by const reference."
"Comparison of modulo result is predetermined"
"Local variable '.*' shadows outer argument"
"Redundant initialization for '.*'. The initialized value is overwritten before it is read."
"Dereferencing '.*' after it is deallocated / released"
"The scope of the variable '.*' can be reduced."
"Parameter '.*' can be declared with const"
"Variable '.*' can be declared with const"
"Variable '.*' is assigned a value that is never used."
"Unused variable"
"The function '.*' overrides a function in a base class but is not marked with a 'override' specifier."
# Enabale to catch all warnings
".*"
)
IGNORED_WARNINGS=(
"src/bls/bls.h:.* Struct 'CBLSIdImplicit' has a constructor with 1 argument that is not explicit."
"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"
feat: mnlistdiff v20 CL sig quorums (#5377) ## Issue being fixed or feature implemented Implementation of Randomness Beacon Part 3. Starting from v20 activation fork, members for quorums are sorted using (if available) the best CL signature found in Coinbase. If no CL signature is present yet, then the usual way is used (By using Blockhash instead) The actual new way to shuffle is already implemented in https://github.com/dashpay/dash/pull/5366. SPV clients also need to calculate members, but they only know block headers. Since Coinbase is in the actual block, then they lack the required information to correctly calculate quorum members. ## What was done? - Message `MNLISTIDFF` is enriched with a new field `quorumsCLSigs`. This field holds the Chainlock Signature required for each set of indexes corresponding to quorums in field `newQuorums`. - Protocol version has been bumped to `70230`. - Clients with protocol version greater or equal to `70230` will receive the new field `quorumsCLSigs`. - The same field is returned in `protx diff` RPC. Note: - Field `quorumsCLSigs` will populated only after v20 activation - If for one or more quorums, no non-null CL sig was found in CbTx then a null signature is returned in `quorumsCLSigs`. ## How Has This Been Tested? - Functional test mininode's protocol version was bumped to `70230`. - `feature_llmq_rotation.py` checks that `quorumsCLSigs` match in both P2P and RPC messages. ## Breaking Changes No ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ --------- Co-authored-by: thephez <thephez@users.noreply.github.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com> Co-authored-by: pasta <pasta@dashboost.org>
2023-07-10 18:23:09 +02:00
"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\]"
"src/rpc/.*cpp:.*: note: Function pointer used here."
"src/masternode/sync.cpp:.*: warning: Variable 'pnode' can be declared as pointer to const \[constVariableReference\]"
"src/wallet/bip39.cpp.*: warning: The scope of the variable 'ssCurrentWord' can be reduced. \[variableScope\]"
"src/stacktraces.cpp:.*: .*: Parameter 'info' can be declared as pointer to const"
"src/stacktraces.cpp:.*: note: You might need to cast the function pointer here"
"[note|warning]: Return value 'state.Invalid(.*)' is always false"
"note: Calling function 'Invalid' returns 0"
# General catchall, for some reason any value named 'hash' is viewed as never used.
"Variable 'hash' is assigned a value that is never used."
# The following can be useful to ignore when the catch all is used
# "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::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."
"unusedFunction"
"unknownMacro"
"unusedStructMember"
)
# We should attempt to update this with all dash specific code
FILES=$(git ls-files -- $(cat test/util/data/non-backported.txt))
if ! command -v cppcheck > /dev/null; then
echo "Skipping cppcheck linting since cppcheck is not installed."
exit 0
fi
function join_array {
local IFS="$1"
shift
echo "$*"
}
ENABLED_CHECKS_REGEXP=$(join_array "|" "${ENABLED_CHECKS[@]}")
IGNORED_WARNINGS_REGEXP=$(join_array "|" "${IGNORED_WARNINGS[@]}")
FILES_REGEXP=$(join_array "|" "${FILES[@]}")
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CPPCHECK_DIR=$SCRIPT_DIR/.cppcheck/
if [ ! -d $CPPCHECK_DIR ]
then
mkdir $CPPCHECK_DIR
fi
WARNINGS=$(echo "${FILES}" | \
test: multiple linter warnings to suppress or fix (#5880) ## Issue being fixed or feature implemented On my local kubuntu linters have way too much spam ## What was done? See each commit ## How Has This Been Tested? Run locally. Amount of warnings decreased from thousands to fewer amount. Excluding typos, they are: ``` src/coinjoin/client.cpp:1420:5: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/coinjoin/client.cpp:1426:5: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/coinjoin/client.cpp:655:26: warning: Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm] src/coinjoin/server.cpp:593:33: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/coinjoin/server.cpp:630:106: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/governance/governance.cpp:1057:9: warning: C-style pointer casting [cstyleCast] src/governance/governance.cpp:1068:9: warning: C-style pointer casting [cstyleCast] src/governance/governance.cpp:1079:13: warning: C-style pointer casting [cstyleCast] src/governance/governance.cpp:1086:9: warning: C-style pointer casting [cstyleCast] src/governance/governance.cpp:1094:9: warning: C-style pointer casting [cstyleCast] src/governance/governance.cpp:1099:5: warning: C-style pointer casting [cstyleCast] src/governance/governance.cpp:1486:34: warning: Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm] src/llmq/commitment.cpp:102:5: warning: Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm] src/llmq/instantsend.cpp:820:38: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/llmq/quorums.cpp:831:102: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/llmq/quorums.h:300:17: warning: C-style pointer casting [cstyleCast] src/llmq/quorums.h:301:17: warning: C-style pointer casting [cstyleCast] src/llmq/quorums.h:302:17: warning: C-style pointer casting [cstyleCast] src/llmq/quorums.h:303:17: warning: C-style pointer casting [cstyleCast] src/spork.cpp:119:58: warning: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm] src/statsd_client.cpp:234:63: warning: C-style pointer casting [cstyleCast] Advice not applicable in this specific case? Add an exception by updating IGNORED_WARNINGS in test/lint/lint-cppcheck-dash.sh ^---- failure generated from test/lint/lint-cppcheck-dash.sh Consider install flake8-cached for cached flake8 results. test/functional/data/invalid_txs.py: error: Source file found twice under different module names: "invalid_txs" and "data.invalid_txs" test/functional/data/invalid_txs.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info test/functional/data/invalid_txs.py: note: Common resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH Found 1 error in 1 file (errors prevented further checking) ^---- failure generated from test/lint/lint-python.s ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-02-20 15:22:37 +01:00
xargs cppcheck --enable=all --inline-suppr --suppress=missingIncludeSystem --cppcheck-build-dir=$CPPCHECK_DIR -j "$(getconf _NPROCESSORS_ONLN)" --language=c++ --std=c++17 --template=gcc -D__cplusplus -DENABLE_WALLET -DCLIENT_VERSION_BUILD -DCLIENT_VERSION_IS_RELEASE -DCLIENT_VERSION_MAJOR -DCLIENT_VERSION_MINOR -DCOPYRIGHT_YEAR -DDEBUG -DCHAR_BIT=8 -I src/ -q 2>&1 | sort -u | \
grep -E "${ENABLED_CHECKS_REGEXP}" | \
grep -vE "${IGNORED_WARNINGS_REGEXP}" | \
grep -E "${FILES_REGEXP}")
if [[ ${WARNINGS} != "" ]]; then
echo "${WARNINGS}"
echo
echo "Advice not applicable in this specific case? Add an exception by updating"
echo "IGNORED_WARNINGS in $0"
# Uncomment to enforce the linter / comment to run locally
exit 1
fi
exit 0