Set default JSON parser flags

This commit is contained in:
SChernykh 2023-06-12 15:29:23 +02:00
parent 47c79459a6
commit b7ff4f2c2c
6 changed files with 13 additions and 9 deletions

View file

@ -295,6 +295,8 @@ if (HAVE_RES_QUERY)
endif() endif()
endif() endif()
add_definitions("-DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag")
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES}) add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES})
if (STATIC_BINARY OR STATIC_LIBS) if (STATIC_BINARY OR STATIC_LIBS)

View file

@ -1,5 +1,5 @@
@echo off @echo off
"..\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 "..\cppcheck-main\bin\cppcheck.exe" --project=..\build\p2pool.vcxproj --project-configuration="Release|x64" -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN -DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag --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 findstr /V /C:"external\src" errors_full.txt > errors_filtered.txt
for /f %%i in ("errors_filtered.txt") do set size=%%~zi for /f %%i in ("errors_filtered.txt") do set size=%%~zi
if %size% gtr 0 ( if %size% gtr 0 (

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
../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 ../cppcheck-main/cppcheck ../src -DSIZE_MAX=UINT64_MAX -DRAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN -DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag --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 grep -v 'external' errors_full.txt > errors_filtered.txt
if [ -s errors_filtered.txt ]; then if [ -s errors_filtered.txt ]; then
cat errors_filtered.txt cat errors_filtered.txt

View file

@ -607,7 +607,7 @@ void p2pool::submit_block() const
[height, diff, template_id, nonce, extra_nonce, sidechain_id, is_external](const char* data, size_t size) [height, diff, template_id, nonce, extra_nonce, sidechain_id, is_external](const char* data, size_t size)
{ {
rapidjson::Document doc; rapidjson::Document doc;
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) { if (doc.Parse(data, size).HasParseError() || !doc.IsObject()) {
LOGERR(0, "submit_block: invalid JSON response from daemon"); LOGERR(0, "submit_block: invalid JSON response from daemon");
return; return;
} }
@ -919,7 +919,7 @@ void p2pool::parse_get_info_rpc(const char* data, size_t size)
} }
rapidjson::Document doc; rapidjson::Document doc;
doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size); doc.Parse(data, size);
if (!doc.IsObject() || !doc.HasMember("result")) { if (!doc.IsObject() || !doc.HasMember("result")) {
LOGWARN(1, "get_info RPC response is invalid (\"result\" not found), trying again in 1 second"); LOGWARN(1, "get_info RPC response is invalid (\"result\" not found), trying again in 1 second");
@ -1003,7 +1003,7 @@ void p2pool::parse_get_version_rpc(const char* data, size_t size)
} }
rapidjson::Document doc; rapidjson::Document doc;
doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size); doc.Parse(data, size);
if (!doc.IsObject() || !doc.HasMember("result")) { if (!doc.IsObject() || !doc.HasMember("result")) {
LOGWARN(1, "get_version RPC response is invalid (\"result\" not found), trying again in 1 second"); LOGWARN(1, "get_version RPC response is invalid (\"result\" not found), trying again in 1 second");
@ -1090,7 +1090,7 @@ void p2pool::parse_get_miner_data_rpc(const char* data, size_t size)
m_getMinerDataHash = h; m_getMinerDataHash = h;
rapidjson::Document doc; rapidjson::Document doc;
doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size); doc.Parse(data, size);
if (!doc.IsObject() || !doc.HasMember("result")) { if (!doc.IsObject() || !doc.HasMember("result")) {
LOGWARN(1, "get_miner_data RPC response is invalid, skipping it"); LOGWARN(1, "get_miner_data RPC response is invalid, skipping it");
@ -1140,7 +1140,7 @@ void p2pool::parse_get_miner_data_rpc(const char* data, size_t size)
bool p2pool::parse_block_header(const char* data, size_t size, ChainMain& c) bool p2pool::parse_block_header(const char* data, size_t size, ChainMain& c)
{ {
rapidjson::Document doc; rapidjson::Document doc;
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) { if (doc.Parse(data, size).HasParseError() || !doc.IsObject()) {
LOGERR(1, "parse_block_header: invalid JSON response from daemon"); LOGERR(1, "parse_block_header: invalid JSON response from daemon");
return false; return false;
} }
@ -1182,7 +1182,7 @@ bool p2pool::parse_block_header(const char* data, size_t size, ChainMain& c)
uint32_t p2pool::parse_block_headers_range(const char* data, size_t size) uint32_t p2pool::parse_block_headers_range(const char* data, size_t size)
{ {
rapidjson::Document doc; rapidjson::Document doc;
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) { if (doc.Parse(data, size).HasParseError() || !doc.IsObject()) {
LOGERR(1, "parse_block_headers_range: invalid JSON response from daemon"); LOGERR(1, "parse_block_headers_range: invalid JSON response from daemon");
return 0; return 0;
} }

View file

@ -206,7 +206,7 @@ void ZMQReader::parse(char* data, size_t size)
using namespace rapidjson; using namespace rapidjson;
Document doc; Document doc;
if (doc.Parse<kParseCommentsFlag | kParseTrailingCommasFlag>(value, end - value).HasParseError()) { if (doc.Parse(value, end - value).HasParseError()) {
LOGWARN(1, "ZeroMQ message failed to parse, skipping it"); LOGWARN(1, "ZeroMQ message failed to parse, skipping it");
return; return;
} }

View file

@ -174,6 +174,8 @@ if (HAVE_BITSCANREVERSE64)
add_definitions(/DHAVE_BITSCANREVERSE64) add_definitions(/DHAVE_BITSCANREVERSE64)
endif() endif()
add_definitions("-DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag")
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES}) add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} debug ${ZMQ_LIBRARY_DEBUG} debug ${UV_LIBRARY_DEBUG} debug ${CURL_LIBRARY_DEBUG} optimized ${ZMQ_LIBRARY} optimized ${UV_LIBRARY} optimized ${CURL_LIBRARY} ${LIBS}) target_link_libraries(${CMAKE_PROJECT_NAME} debug ${ZMQ_LIBRARY_DEBUG} debug ${UV_LIBRARY_DEBUG} debug ${CURL_LIBRARY_DEBUG} optimized ${ZMQ_LIBRARY} optimized ${UV_LIBRARY} optimized ${CURL_LIBRARY} ${LIBS})
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/src/crypto_tests.txt" $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>) add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/src/crypto_tests.txt" $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>)