From 4deef2f807788111e725359a8cdf1386c6ba9dff Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 5 Sep 2021 12:51:20 +0200 Subject: [PATCH] Added cppcheck workflow --- .github/workflows/cppcheck.yml | 26 ++++++++++++++++++++++++++ cppcheck/run.sh | 6 +++++- src/crypto.cpp | 2 ++ src/log.cpp | 1 + src/p2pool_api.cpp | 1 + src/pow_hash.cpp | 2 ++ 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cppcheck.yml diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000..8fb54aa --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,26 @@ +name: cppcheck + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + cppcheck-ubuntu: + + 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: Run cppcheck + run: | + cd cppcheck + ./run.sh diff --git a/cppcheck/run.sh b/cppcheck/run.sh index 844cffc..42c4341 100755 --- a/cppcheck/run.sh +++ b/cppcheck/run.sh @@ -1,3 +1,7 @@ #!/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/ --suppressions-list=suppressions.txt --output-file=errors_full.txt -grep -v 'external' errors_full.txt > errors_filtered.txt +grep -v 'external' errors_full.txt | grep -v 'unmatchedSuppression' > errors_filtered.txt +if [ -s errors_filtered.txt ]; then + cat errors_filtered.txt + exit 1 +fi diff --git a/src/crypto.cpp b/src/crypto.cpp index 88938b9..7f34fb4 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -75,6 +75,7 @@ static FORCEINLINE bool less32(const uint8_t* k0, const uint8_t* k1) return false; } +// cppcheck-suppress constParameter void generate_keys(hash& pub, hash& sec) { // l = 2^252 + 27742317777372353535851937790883648493. @@ -152,6 +153,7 @@ static FORCEINLINE void derivation_to_scalar(const hash& derivation, size_t outp hash_to_scalar(begin, end - begin, res); } +// cppcheck-suppress constParameter bool derive_public_key(const hash& derivation, size_t output_index, const hash& base, hash& derived_key) { uint8_t scalar[HASH_SIZE]; diff --git a/src/log.cpp b/src/log.cpp index c6f3945..d358d3a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -240,6 +240,7 @@ 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/p2pool_api.cpp b/src/p2pool_api.cpp index e8a88b1..fad3aa9 100644 --- a/src/p2pool_api.cpp +++ b/src/p2pool_api.cpp @@ -129,6 +129,7 @@ void p2pool_api::dump_to_file() } 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/pow_hash.cpp b/src/pow_hash.cpp index 3e8bc18..53bed68 100644 --- a/src/pow_hash.cpp +++ b/src/pow_hash.cpp @@ -164,6 +164,7 @@ void RandomX_Hasher::set_seed(const hash& seed) } { + // cppcheck-suppress unreadVariable ON_SCOPE_LEAVE([this]() { uv_rwlock_wrunlock(&m_cacheLock); }); if (m_stopped.load()) { @@ -296,6 +297,7 @@ bool RandomX_Hasher::calculate(const void* data, size_t size, const hash& seed, { // 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()) {