From cf325e0e767bc9468c47728aa71feadf1d646789 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:44:08 +0100 Subject: [PATCH] Updated rapidjson --- cppcheck/run.cmd | 12 +++++++++++- cppcheck/run.sh | 9 +++++++++ external/src/rapidjson | 2 +- src/merge_mining_client_json_rpc.cpp | 2 +- src/p2p_server.cpp | 2 +- src/p2pool.cpp | 2 +- src/pow_hash.cpp | 2 +- src/rapidjson_wrapper.h | 5 +++++ src/side_chain.cpp | 4 ++++ src/stratum_server.cpp | 8 ++++++-- src/stratum_server.h | 5 ++--- src/zmq_reader.cpp | 2 +- 12 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 src/rapidjson_wrapper.h diff --git a/cppcheck/run.cmd b/cppcheck/run.cmd index 1c792c0..32c04c0 100644 --- a/cppcheck/run.cmd +++ b/cppcheck/run.cmd @@ -1,9 +1,19 @@ @echo off -"..\cppcheck-main\bin\cppcheck.exe" ../src/*.cpp -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN -D_WIN32=1 -D_WIN64=1 -DWIN32=1 -D_WINDOWS=1 -DNDEBUG=1 -DWITH_GRPC=1 -DPROTOBUF_ENABLE_DEBUG_LOGGING_MAY_LEAK_PII=0 -DWITH_RANDOMX=1 -DWITH_UPNP=1 -DCURL_STATICLIB=1 -DWIN32_LEAN_AND_MEAN=1 -D_WIN32_WINNT=0x0600 -D_DISABLE_VECTOR_ANNOTATION=1 -D_DISABLE_STRING_ANNOTATION=1 -DZMQ_STATIC=1 -DHAVE_BITSCANREVERSE64=1 -DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag -DMINIUPNP_STATICLIB=1 -DCARES_STATICLIB=1 -DCMAKE_INTDIR="Release" -D__SSE2__=1 -D_MSC_VER=1929 -D__COVERITY__ --platform=win64 --std=c++17 --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 --max-ctu-depth=3 --check-level=exhaustive --checkers-report=checkers_report.txt +"..\cppcheck-main\bin\cppcheck.exe" ../src/*.cpp -D__cppcheck__ -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN -D_WIN32=1 -D_WIN64=1 -DWIN32=1 -D_WINDOWS=1 -DNDEBUG=1 -DWITH_GRPC=1 -DPROTOBUF_ENABLE_DEBUG_LOGGING_MAY_LEAK_PII=0 -DWITH_RANDOMX=1 -DWITH_UPNP=1 -DCURL_STATICLIB=1 -DWIN32_LEAN_AND_MEAN=1 -D_WIN32_WINNT=0x0600 -D_DISABLE_VECTOR_ANNOTATION=1 -D_DISABLE_STRING_ANNOTATION=1 -DZMQ_STATIC=1 -DHAVE_BITSCANREVERSE64=1 -DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag -DMINIUPNP_STATICLIB=1 -DCARES_STATICLIB=1 -DCMAKE_INTDIR="Release" -D__SSE2__=1 -D_MSC_VER=1929 -D__COVERITY__ --platform=win64 --std=c++17 --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 --max-ctu-depth=3 --check-level=exhaustive --checkers-report=checkers_report.txt + findstr /V /C:"external\src" errors_full.txt > errors_filtered0.txt findstr /V /C:":checkersReport" errors_filtered0.txt > errors_filtered.txt + +findstr /C:"There were critical errors" checkers_report.txt > checkers_report_filtered.txt + for /f %%i in ("errors_filtered.txt") do set size=%%~zi if %size% gtr 0 ( type errors_filtered.txt exit 1 ) + +for /f %%i in ("checkers_report_filtered.txt") do set size2=%%~zi +if %size2% gtr 0 ( + type checkers_report_filtered.txt + exit 1 +) diff --git a/cppcheck/run.sh b/cppcheck/run.sh index 270b703..8d015c9 100755 --- a/cppcheck/run.sh +++ b/cppcheck/run.sh @@ -1,8 +1,17 @@ #!/bin/bash ../cppcheck-main/cppcheck --project=../build/compile_commands.json -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN -DRAPIDJSON_64BIT=1 -D__SSE2__=1 -D__BYTE_ORDER__=1 -D__ORDER_LITTLE_ENDIAN__=1 -D__linux__=1 -D__x86_64 -D_M_AMD64 -D_M_X64 --platform=unix64 --std=c++17 --enable=all --inconclusive --inline-suppr --template="{file}:{line}:{id}{inconclusive: INCONCLUSIVE} {message}" --suppressions-list=suppressions.txt --output-file=errors_full.txt --max-ctu-depth=3 --check-level=exhaustive --checkers-report=checkers_report.txt + grep -v 'external' errors_full.txt > errors_filtered0.txt grep -v ':checkersReport' errors_filtered0.txt > errors_filtered.txt + +grep 'There were critical errors' checkers_report.txt > checkers_report_filtered.txt + if [ -s errors_filtered.txt ]; then cat errors_filtered.txt exit 1 fi + +if [ -s checkers_report_filtered.txt ]; then + cat checkers_report_filtered.txt + exit 1 +fi diff --git a/external/src/rapidjson b/external/src/rapidjson index 5eb4b23..a6f1188 160000 --- a/external/src/rapidjson +++ b/external/src/rapidjson @@ -1 +1 @@ -Subproject commit 5eb4b2335a3f849c8b421b75354f98a1169fed95 +Subproject commit a6f118884172d86c2bfb6f5adae70bdebc88c059 diff --git a/src/merge_mining_client_json_rpc.cpp b/src/merge_mining_client_json_rpc.cpp index 5ba39bc..7baf1a6 100644 --- a/src/merge_mining_client_json_rpc.cpp +++ b/src/merge_mining_client_json_rpc.cpp @@ -22,7 +22,7 @@ #include "params.h" #include "json_rpc_request.h" #include "json_parsers.h" -#include +#include "rapidjson_wrapper.h" LOG_CATEGORY(MergeMiningClientJSON_RPC) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index fc836c0..0290c78 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -28,7 +28,7 @@ #include "block_template.h" #include "p2pool_api.h" #include "stratum_server.h" -#include +#include "rapidjson_wrapper.h" #include #include diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 2ccc51c..5fff44f 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -20,7 +20,7 @@ #include "zmq_reader.h" #include "mempool.h" #include "json_rpc_request.h" -#include "rapidjson/document.h" +#include "rapidjson_wrapper.h" #include "json_parsers.h" #include "pow_hash.h" #include "block_template.h" diff --git a/src/pow_hash.cpp b/src/pow_hash.cpp index be57bce..7990782 100644 --- a/src/pow_hash.cpp +++ b/src/pow_hash.cpp @@ -26,7 +26,7 @@ #endif #include "json_rpc_request.h" #include "json_parsers.h" -#include +#include "rapidjson_wrapper.h" #include LOG_CATEGORY(RandomX_Hasher) diff --git a/src/rapidjson_wrapper.h b/src/rapidjson_wrapper.h new file mode 100644 index 0000000..a0b1843 --- /dev/null +++ b/src/rapidjson_wrapper.h @@ -0,0 +1,5 @@ +#if defined(_MSC_VER) && defined(__cppcheck__) +// cppcheck chokes on rapidjson headers in Windows +#else +#include +#endif diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 896916a..2c61564 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -34,8 +34,12 @@ #include "json_parsers.h" #include "crypto.h" #include "hardforks/hardforks.h" + +#if !defined(_MSC_VER) || !defined(__cppcheck__) #include #include +#endif + #include #include #include diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index db07017..de7909e 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -24,6 +24,8 @@ #include "p2pool_api.h" #include "p2p_server.h" +#include "rapidjson_wrapper.h" + LOG_CATEGORY(StratumServer) static constexpr int DEFAULT_BACKLOG = 128; @@ -1311,7 +1313,8 @@ bool StratumServer::StratumClient::process_request(char* data, uint32_t size) return false; } -bool StratumServer::StratumClient::process_login(rapidjson::Document& doc, uint32_t id) +template +bool StratumServer::StratumClient::process_login(T& doc, uint32_t id) { const auto params_it = doc.FindMember("params"); if (params_it == doc.MemberEnd()) { @@ -1340,7 +1343,8 @@ bool StratumServer::StratumClient::process_login(rapidjson::Document& doc, uint3 return static_cast(m_owner)->on_login(this, id, login.GetString()); } -bool StratumServer::StratumClient::process_submit(rapidjson::Document& doc, uint32_t id) +template +bool StratumServer::StratumClient::process_submit(T& doc, uint32_t id) { const auto params_it = doc.FindMember("params"); if (params_it == doc.MemberEnd()) { diff --git a/src/stratum_server.h b/src/stratum_server.h index bc0b8b2..772fb65 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -18,7 +18,6 @@ #pragma once #include "tcp_server.h" -#include namespace p2pool { @@ -50,8 +49,8 @@ public: [[nodiscard]] bool on_read(const char* data, uint32_t size) override; [[nodiscard]] bool process_request(char* data, uint32_t size); - [[nodiscard]] bool process_login(rapidjson::Document& doc, uint32_t id); - [[nodiscard]] bool process_submit(rapidjson::Document& doc, uint32_t id); + template [[nodiscard]] bool process_login(T& doc, uint32_t id); + template [[nodiscard]] bool process_submit(T& doc, uint32_t id); bool send_http_response(bool send_content); diff --git a/src/zmq_reader.cpp b/src/zmq_reader.cpp index af81149..d40f4c8 100644 --- a/src/zmq_reader.cpp +++ b/src/zmq_reader.cpp @@ -18,7 +18,7 @@ #include "common.h" #include "zmq_reader.h" #include "json_parsers.h" -#include +#include "rapidjson_wrapper.h" LOG_CATEGORY(ZMQReader)