diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index 7c58d4c..686b810 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -12,14 +12,22 @@ jobs: runs-on: ubuntu-latest steps: - - name: Install cppcheck - run: sudo apt update && sudo apt install cppcheck - - name: Checkout repository uses: actions/checkout@v2 with: submodules: true + - name: Checkout cppcheck + uses: actions/checkout@v3 + with: + repository: danmar/cppcheck + path: cppcheck-main + + - name: Build cppcheck + run: | + cd cppcheck-main + make -j$(nproc) cppcheck + - name: Run cppcheck run: | cd cppcheck @@ -27,7 +35,7 @@ jobs: cppcheck-windows: - runs-on: windows-2022 + runs-on: windows-latest steps: - name: Checkout repository diff --git a/cppcheck/includes.txt b/cppcheck/includes.txt index a004882..87aed99 100644 --- a/cppcheck/includes.txt +++ b/cppcheck/includes.txt @@ -1,9 +1,9 @@ ../src/ ../external/src/ ../external/src/cryptonote/ -../external/src/libuv/ +../external/src/libuv/include/ ../external/src/cppzmq/ -../external/src/libzmq/ +../external/src/libzmq/include/ ../external/src/llhttp/ ../external/src/RandomX/src/ ../external/src/rapidjson/include diff --git a/cppcheck/run.cmd b/cppcheck/run.cmd index e15acd6..4880223 100644 --- a/cppcheck/run.cmd +++ b/cppcheck/run.cmd @@ -1,5 +1,5 @@ @echo off -"..\cppcheck-main\bin\cppcheck.exe" --project=..\build\p2pool.vcxproj --project-configuration="Release|x64" -DZMQ_STATIC --platform=win64 --std=c++14 --enable=all --inconclusive --inline-suppr --template="{file}:{line}:{id}{inconclusive: INCONCLUSIVE} {message}" --includes-file=includes.txt --suppressions-list=suppressions.txt --output-file=errors_full.txt +"..\cppcheck-main\bin\cppcheck.exe" --project=..\build\p2pool.vcxproj --project-configuration="Release|x64" -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN --platform=win64 --std=c++14 --enable=all --inconclusive --inline-suppr --template="{file}:{line}:{id}{inconclusive: INCONCLUSIVE} {message}" --includes-file=includes.txt --suppressions-list=suppressions.txt --output-file=errors_full.txt findstr /V /C:"external\src" errors_full.txt > errors_filtered.txt for /f %%i in ("errors_filtered.txt") do set size=%%~zi if %size% gtr 0 ( diff --git a/cppcheck/run.sh b/cppcheck/run.sh index 243d262..a1761d1 100755 --- a/cppcheck/run.sh +++ b/cppcheck/run.sh @@ -1,6 +1,6 @@ #!/bin/bash -cppcheck ../src -DZMQ_STATIC --platform=unix64 --std=c++14 --enable=all --inconclusive --inline-suppr --template="{file}:{line}:{id}{inconclusive: INCONCLUSIVE} {message}" -I ../src/ -I ../external/src/ -I ../external/src/cryptonote/ -I ../external/src/libuv/ -I ../external/src/cppzmq/ -I ../external/src/libzmq/ -I ../external/src/llhttp/ -I ../external/src/RandomX/src/ -I ../external/src/rapidjson/include -I ../external/src/robin-hood-hashing/src/include --suppressions-list=suppressions.txt --output-file=errors_full.txt -grep -v 'external' errors_full.txt | grep -v 'unmatchedSuppression' > errors_filtered.txt +../cppcheck-main/cppcheck ../src -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN --platform=unix64 --std=c++14 --enable=all --inconclusive --inline-suppr --template="{file}:{line}:{id}{inconclusive: INCONCLUSIVE} {message}" --includes-file=includes.txt --suppressions-list=suppressions.txt --output-file=errors_full.txt +grep -v 'external' errors_full.txt > errors_filtered.txt if [ -s errors_filtered.txt ]; then cat errors_filtered.txt exit 1 diff --git a/cppcheck/suppressions.txt b/cppcheck/suppressions.txt index 127f474..d4317c5 100644 --- a/cppcheck/suppressions.txt +++ b/cppcheck/suppressions.txt @@ -1,6 +1,3 @@ missingIncludeSystem unusedFunction useStlAlgorithm -functionStatic -functionConst -unmatchedSuppression diff --git a/src/block_template.h b/src/block_template.h index 1d02a2d..1b988a0 100644 --- a/src/block_template.h +++ b/src/block_template.h @@ -55,7 +55,6 @@ public: void submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce); - FORCEINLINE uint64_t final_reward() const { return m_finalReward; } FORCEINLINE const std::vector& shares() const { return m_shares; } private: diff --git a/src/crypto.cpp b/src/crypto.cpp index bb83231..0f9b4e1 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -238,6 +238,7 @@ private: struct DerivationEntry { hash derivation; + // cppcheck-suppress unusedStructMember uint8_t view_tag; }; diff --git a/src/json_rpc_request.h b/src/json_rpc_request.h index e1d5a85..1061ce9 100644 --- a/src/json_rpc_request.h +++ b/src/json_rpc_request.h @@ -71,6 +71,7 @@ private: static void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); void on_read(const char* data, size_t size); + // cppcheck-suppress functionConst void close(); static void on_close(uv_handle_t* handle); diff --git a/src/keccak.cpp b/src/keccak.cpp index aefda85..126178d 100644 --- a/src/keccak.cpp +++ b/src/keccak.cpp @@ -140,7 +140,7 @@ NOINLINE void keccak(const uint8_t* in, int inlen, uint8_t* md, int mdlen) temp[rsiz - 1] |= 0x80; for (int i = 0; i < rsizw; i++) { - st[i] ^= ((uint64_t*)temp)[i]; + st[i] ^= reinterpret_cast(temp)[i]; } keccakf(st); diff --git a/src/log.cpp b/src/log.cpp index 402d69f..7ca51f9 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -276,7 +276,6 @@ static Worker worker; #endif // P2POOL_LOG_DISABLE -// cppcheck-suppress uninitMemberVar NOINLINE Writer::Writer(Severity severity) : Stream(m_stackBuf) { m_buf[0] = static_cast(severity); diff --git a/src/log.h b/src/log.h index a0802e6..f901529 100644 --- a/src/log.h +++ b/src/log.h @@ -378,7 +378,6 @@ template<> struct log::Stream::Entry template<> struct log::Stream::Entry { - // cppcheck-suppress constParameter static NOINLINE void put(NetworkType value, Stream* wrapper) { switch (value) { diff --git a/src/memory_leak_debug.cpp b/src/memory_leak_debug.cpp index 2527b0f..c9022ec 100644 --- a/src/memory_leak_debug.cpp +++ b/src/memory_leak_debug.cpp @@ -236,7 +236,9 @@ NOINLINE void operator delete(void* p, size_t) noexcept { p2pool::free_hook(p); NOINLINE void operator delete[](void* p, size_t) noexcept { p2pool::free_hook(p); } #else +// cppcheck-suppress functionStatic void memory_tracking_start() {} +// cppcheck-suppress functionStatic void memory_tracking_stop() {} namespace p2pool { diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index abd12a8..2a88c16 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -151,6 +151,7 @@ void P2PServer::clear_cached_blocks() WriteLock lock(m_cachedBlocksLock); + // cppcheck-suppress identicalConditionAfterEarlyExit if (!m_cachedBlocks) { return; } diff --git a/src/p2pool_api.cpp b/src/p2pool_api.cpp index 8b7bd9a..f5ea9c0 100644 --- a/src/p2pool_api.cpp +++ b/src/p2pool_api.cpp @@ -131,12 +131,10 @@ void p2pool_api::dump_to_file() { MutexLock lock(m_dumpDataLock); data = std::move(m_dumpData); - // cppcheck-suppress accessMoved m_dumpData.clear(); } for (auto& it : data) { - // cppcheck-suppress uninitvar DumpFileWork* work = new DumpFileWork{ {}, {}, {}, it.first, std::move(it.second) }; work->open_req.data = work; work->write_req.data = work; diff --git a/src/p2pool_api.h b/src/p2pool_api.h index 130d669..a0721d4 100644 --- a/src/p2pool_api.h +++ b/src/p2pool_api.h @@ -34,6 +34,7 @@ public: LOCAL, }; + // cppcheck-suppress functionConst void on_stop(); template diff --git a/src/pool_block_parser.inl b/src/pool_block_parser.inl index 9849d4a..aa4cafa 100644 --- a/src/pool_block_parser.inl +++ b/src/pool_block_parser.inl @@ -187,7 +187,6 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, SideChain& sidechai const int sidechain_hash_offset = static_cast((data - data_begin) + outputs_blob_size_diff); READ_BUF(m_sidechainId.h, HASH_SIZE); - // cppcheck-suppress duplicateExpression if (static_cast(data - tx_extra_begin) != tx_extra_size) return __LINE__; EXPECT_BYTE(0); diff --git a/src/pow_hash.cpp b/src/pow_hash.cpp index f057ac7..314d5a3 100644 --- a/src/pow_hash.cpp +++ b/src/pow_hash.cpp @@ -180,7 +180,6 @@ void RandomX_Hasher::set_seed(const hash& seed) } { - // cppcheck-suppress unreadVariable ON_SCOPE_LEAVE([this]() { uv_rwlock_wrunlock(&m_cacheLock); }); if (m_stopped.load()) { @@ -327,7 +326,6 @@ bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height* { // First try to use the dataset if it's ready if (uv_rwlock_tryrdlock(&m_datasetLock) == 0) { - // cppcheck-suppress unreadVariable ON_SCOPE_LEAVE([this]() { uv_rwlock_rdunlock(&m_datasetLock); }); if (m_stopped.load()) { diff --git a/src/side_chain.cpp b/src/side_chain.cpp index a4af8b9..85ffc51 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -172,7 +172,7 @@ SideChain::~SideChain() } } -void SideChain::fill_sidechain_data(PoolBlock& block, Wallet* w, const hash& txkeySec, std::vector& shares) const +void SideChain::fill_sidechain_data(PoolBlock& block, const Wallet* w, const hash& txkeySec, std::vector& shares) const { ReadLock lock(m_sidechainLock); @@ -228,11 +228,8 @@ void SideChain::fill_sidechain_data(PoolBlock& block, Wallet* w, const hash& txk bool same_chain = false; do { tmp = tip; - while (tmp->m_sidechainHeight > uncle->m_sidechainHeight) { + while (tmp && (tmp->m_sidechainHeight > uncle->m_sidechainHeight)) { tmp = get_parent(tmp); - if (!tmp) { - break; - } } if (!tmp || (tmp->m_sidechainHeight < uncle->m_sidechainHeight)) { break; @@ -1530,7 +1527,7 @@ bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candida // If these two blocks are on the same chain, they must have a common ancestor const PoolBlock* block_ancestor = block; - while (block_ancestor->m_sidechainHeight > candidate->m_sidechainHeight) { + while (block_ancestor && (block_ancestor->m_sidechainHeight > candidate->m_sidechainHeight)) { const hash& id = block_ancestor->m_parent; block_ancestor = get_parent(block_ancestor); if (!block_ancestor) { diff --git a/src/side_chain.h b/src/side_chain.h index 8907ff1..aaf0723 100644 --- a/src/side_chain.h +++ b/src/side_chain.h @@ -43,7 +43,7 @@ public: SideChain(p2pool* pool, NetworkType type, const char* pool_name = nullptr); ~SideChain(); - void fill_sidechain_data(PoolBlock& block, Wallet* w, const hash& txkeySec, std::vector& shares) const; + void fill_sidechain_data(PoolBlock& block, const Wallet* w, const hash& txkeySec, std::vector& shares) const; bool block_seen(const PoolBlock& block); void unsee_block(const PoolBlock& block); diff --git a/src/tcp_server.inl b/src/tcp_server.inl index 84d3325..7901fa0 100644 --- a/src/tcp_server.inl +++ b/src/tcp_server.inl @@ -72,6 +72,7 @@ TCPServer::TCPServer(allocate_client_callback all } template +// cppcheck-suppress functionStatic TCPServer::~TCPServer() { if (m_finished.load() == 0) { diff --git a/src/wallet.cpp b/src/wallet.cpp index 940cf55..874cd76 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -89,7 +89,6 @@ Wallet::Wallet(const Wallet& w) operator=(w); } -// cppcheck-suppress operatorEqVarError Wallet& Wallet::operator=(const Wallet& w) { if (this == &w) { @@ -119,7 +118,7 @@ bool Wallet::decode(const char* address) static_assert(last_block_size_index >= 0, "Check ADDRESS_LENGTH"); - uint8_t data[static_cast(num_full_blocks) * sizeof(uint64_t) + last_block_size_index]; + uint8_t data[static_cast(num_full_blocks) * sizeof(uint64_t) + last_block_size_index] = {}; int data_index = 0; for (int i = 0; i <= num_full_blocks; ++i) {