Skip to content

Commit ffa67f7

Browse files
Merge dashpay#7042: fix: re-enable cppcheck and bump its version
9bde19e test: more clear names of white & black list for cpp check: ALWAYS_ENABLED_WARNINGS / SUPPRESSED_WARNINGS (Konstantin Akimov) cefc57a fix: ignore unexpected cppcheck for some files (Konstantin Akimov) 1b2900b test: remove unused exceptions for cppcheck (Konstantin Akimov) fbac886 fix: re-active cppcheck (Konstantin Akimov) 78e613a ci: bump cppcheck version in a container to 2.17.1 (Konstantin Akimov) 72d1d34 refactor: fix cppcheck warning for cachemultimap.h (Konstantin Akimov) 8e064b3 refactor: fix warnings of cppcheck for netinfo.h (Konstantin Akimov) ec8a438 test: run cpp-check with --check-level=exhaustive (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented The previous logic had an intersection of black & white list for exception, and only warnings that got in the white list have been shown. Everything that has not been matched with whitelist should be filtered by blacklist (exceptions), but not only whitelist matches ## What was done? - fixed blacklist & whitelist filtering - bump cpp-check to 2.17.1 (from 2.13.0) - removed outdated exceptions for cppcheck - added new exception for cppcheck - fixed warnings in `evo/mninfo.h` and `cachemultimap.h` ## How Has This Been Tested? Run locally ## 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 ACKs for top commit: UdjinM6: utACK 9bde19e Tree-SHA512: b115a17d4b6911d1bbd529122fd979364ef07f2847f87a79caa94ee59a7e1a8f6b3fe8b811aa2bd30954d3b097d5f01952613105a3d6d755ce5102f4fdf7c47a
2 parents 9cf919c + 9bde19e commit ffa67f7

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

contrib/containers/ci/ci-slim.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Builder for cppcheck
22
FROM debian:bookworm-slim AS cppcheck-builder
3-
ARG CPPCHECK_VERSION=2.13.0
3+
ARG CPPCHECK_VERSION=2.17.1
44
RUN set -ex; \
55
apt-get update && apt-get install -y --no-install-recommends \
66
curl \

src/cachemultimap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ class CacheMultiMap
150150
if(mit == mapIndex.end()) {
151151
return;
152152
}
153-
it_map_t& mapIt = mit->second;
153+
const it_map_t& mapIt = mit->second;
154154

155-
for(it_map_it it = mapIt.begin(); it != mapIt.end(); ++it) {
156-
listItems.erase(it->second);
155+
for (const auto& it : mapIt) {
156+
listItems.erase(it.second);
157157
}
158158

159159
mapIndex.erase(mit);

src/evo/netinfo.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class DomainPort
176176
DomainPort::Status Set(const std::string& addr, const uint16_t port);
177177
DomainPort::Status Validate() const;
178178
uint16_t GetPort() const { return m_port; }
179-
std::string ToStringAddr() const { return m_addr; }
179+
const std::string& ToStringAddr() const { return m_addr; }
180180
std::string ToStringAddrPort() const { return strprintf("%s:%d", m_addr, m_port); }
181181
};
182182

@@ -312,8 +312,6 @@ class MnNetInfo final : public NetInfoInterface
312312
template <typename Stream>
313313
MnNetInfo(deserialize_type, Stream& s) { s >> *this; }
314314

315-
~MnNetInfo() = default;
316-
317315
template <typename Stream>
318316
void Serialize(Stream& s) const
319317
{
@@ -398,8 +396,6 @@ class ExtNetInfo final : public NetInfoInterface
398396
template <typename Stream>
399397
ExtNetInfo(deserialize_type, Stream& s) { s >> *this; }
400398

401-
~ExtNetInfo() = default;
402-
403399
template <typename Stream>
404400
void Serialize(Stream& s) const
405401
{

test/lint/lint-cppcheck-dash.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
os.environ['LC_ALL'] = 'C'
1717

18-
ENABLED_CHECKS = (
18+
ALWAYS_ENABLED_WARNINGS = (
1919
"Class '.*' has a constructor with 1 argument that is not explicit.",
2020
"Struct '.*' has a constructor with 1 argument that is not explicit.",
2121
"Function parameter '.*' should be passed by const reference.",
@@ -33,26 +33,13 @@
3333
# ".*",
3434
)
3535

36-
IGNORED_WARNINGS = (
37-
"src/bls/bls.h:.* Struct 'CBLSIdImplicit' has a constructor with 1 argument that is not explicit.",
38-
"src/rpc/masternode.cpp:.*:21: warning: Consider using std::copy algorithm instead of a raw loop.", # UniValue doesn't support std::copy
39-
"src/cachemultimap.h:.*: warning: Variable 'mapIt' can be declared as reference to const",
40-
"src/evo/simplifiedmns.cpp:.*:20: warning: Consider using std::copy algorithm instead of a raw loop.",
41-
"src/llmq/commitment.cpp.* warning: Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]",
42-
"src/rpc/.*cpp:.*: note: Function pointer used here.",
43-
"src/masternode/sync.cpp:.*: warning: Variable 'pnode' can be declared as pointer to const [constVariableReference]",
44-
"src/wallet/bip39.cpp.*: warning: The scope of the variable 'ssCurrentWord' can be reduced. [variableScope]",
45-
"src/.*:.*: warning: Local variable '_' shadows outer function [shadowFunction]",
46-
36+
SUPPRESSED_WARNINGS = (
4737
"src/stacktraces.cpp:.*: .*: Parameter 'info' can be declared as pointer to const",
4838
"src/stacktraces.cpp:.*: note: You might need to cast the function pointer here",
4939

50-
"[note|warning]: Return value 'state.Invalid(.*)' is always false",
51-
"note: Calling function 'Invalid' returns 0",
52-
"note: Shadow variable",
53-
54-
# General catchall, for some reason any value named 'hash' is viewed as never used.
55-
"Variable 'hash' is assigned a value that is never used.",
40+
# current version of cppcheck fails with this error if exhaustive level is used
41+
# TODO: remove with a newer version
42+
"warning: Internal error: Child process crashed with signal 6",
5643

5744
# The following can be useful to ignore when the catch all is used
5845
# "Consider performing initialization in initialization list.",
@@ -85,8 +72,8 @@ def main():
8572
files_output = subprocess.check_output(['git', 'ls-files', '--'] + patterns, universal_newlines=True, encoding="utf8")
8673
files = [f.strip() for f in files_output.splitlines() if f.strip()]
8774

88-
enabled_regexp = '|'.join(ENABLED_CHECKS)
89-
ignored_regexp = '|'.join(IGNORED_WARNINGS)
75+
always_enabled_regexp = '|'.join(ALWAYS_ENABLED_WARNINGS)
76+
suppressed_regexp = '|'.join(SUPPRESSED_WARNINGS)
9077
files_regexp = '|'.join(re.escape(f) for f in files)
9178

9279
script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -107,6 +94,7 @@ def main():
10794
'--language=c++',
10895
'--std=c++20',
10996
'--template=gcc',
97+
'--check-level=exhaustive',
11098
'-D__cplusplus',
11199
'-DENABLE_WALLET',
112100
'-DCLIENT_VERSION_BUILD',
@@ -130,14 +118,16 @@ def main():
130118

131119
unique_sorted_lines = sorted(set(dependencies_output.stdout.splitlines()))
132120
for line in unique_sorted_lines:
133-
if re.search(enabled_regexp, line) and not re.search(ignored_regexp, line) and re.search(files_regexp, line):
121+
if not re.search(files_regexp, line):
122+
continue
123+
if re.search(always_enabled_regexp, line) or not re.search(suppressed_regexp, line):
134124
warnings.append(line)
135125

136126
if warnings:
137127
print('\n'.join(warnings))
138128
print()
139129
print("Advice not applicable in this specific case? Add an exception by updating")
140-
print(f"IGNORED_WARNINGS in {__file__}")
130+
print(f"SUPPRESSED_WARNINGS in {__file__}")
141131
# Uncomment to enforce the linter / comment to run locally
142132
exit_code = 1
143133

0 commit comments

Comments
 (0)