From f7dd28002ec6b7633c16b47522e2f90ed3661e9c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 4 Jan 2023 14:03:09 +0100 Subject: [PATCH] build: Build everything using `-Wpedantic` --- cmake/build_helpers.cmake | 3 +-- lib/external/pattern_language | 2 +- lib/external/yara/CMakeLists.txt | 25 ++++++++++--------- lib/libimhex/source/helpers/file.cpp | 2 +- lib/libimhex/source/helpers/magic.cpp | 12 ++++++--- lib/libimhex/source/helpers/utils.cpp | 7 +++--- .../source/content/data_visualizers.cpp | 8 +++--- .../source/content/views/view_find.cpp | 21 ++++++++++++---- .../source/content/views/view_yara.cpp | 5 ++++ tests/algorithms/CMakeLists.txt | 2 +- tests/common/CMakeLists.txt | 2 +- tests/helpers/CMakeLists.txt | 2 +- 12 files changed, 56 insertions(+), 35 deletions(-) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index a51112bfc..2b07a07a2 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -383,7 +383,7 @@ function(downloadImHexPatternsFiles dest) endfunction() macro(setupCompilerWarnings target) - set(IMHEX_COMMON_FLAGS "-Wall -Wextra -Werror") + set(IMHEX_COMMON_FLAGS "-Wall -Wextra -Wpedantic -Werror") set(IMHEX_C_FLAGS "${IMHEX_COMMON_FLAGS} -Wno-restrict -Wno-stringop-overread -Wno-stringop-overflow") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IMHEX_C_FLAGS}") @@ -409,7 +409,6 @@ macro(addBundledLibraries) set(EXTERN_LIBS_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/lib/external") - set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable building of shared libraries") add_subdirectory(${EXTERN_LIBS_FOLDER}/imgui) set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/lib/external/pattern_language b/lib/external/pattern_language index fb427b82a..4dec3adf6 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit fb427b82a99076fdc3babaf0e2f5cb4717dac835 +Subproject commit 4dec3adf6e2a8369569d64a6fe2c46b7c09f5943 diff --git a/lib/external/yara/CMakeLists.txt b/lib/external/yara/CMakeLists.txt index 4318f5e82..dc67bdc50 100644 --- a/lib/external/yara/CMakeLists.txt +++ b/lib/external/yara/CMakeLists.txt @@ -95,23 +95,24 @@ set(LIBYARA_MODULES ${LIBYARA_SOURCE_PATH}/modules/time/time.c ) -# Add mbedtls crypto wrappers -add_compile_definitions("HAVE_MBEDTLS") - -add_compile_definitions("USE_NO_PROC") - -add_compile_definitions("HASH_MODULE") -add_compile_definitions("DOTNET_MODULE") -add_compile_definitions("MAGIC_MODULE") -add_compile_definitions("MACHO_MODULE") -add_compile_definitions("DEX_MODULE") - find_package(mbedTLS 2.26.0 REQUIRED) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shift-count-overflow") add_library(libyara STATIC ${LIBYARA_SOURCE} ${LIBYARA_INCLUDES} ${LIBYARA_MODULES}) set_property(TARGET libyara PROPERTY POSITION_INDEPENDENT_CODE ON) +# Add mbedtls crypto wrappers +target_compile_definitions(libyara PRIVATE HAVE_MBEDTLS) + +target_compile_definitions(libyara PRIVATE USE_NO_PROC) + +target_compile_definitions(libyara PRIVATE HASH_MODULE) +target_compile_definitions(libyara PRIVATE DOTNET_MODULE) +target_compile_definitions(libyara PRIVATE MAGIC_MODULE) +target_compile_definitions(libyara PRIVATE MACHO_MODULE) +target_compile_definitions(libyara PRIVATE DEX_MODULE) + +target_compile_options(libyara PRIVATE "-Wno-shift-count-overflow") + target_include_directories( libyara PUBLIC $ $ $ diff --git a/lib/libimhex/source/helpers/file.cpp b/lib/libimhex/source/helpers/file.cpp index 5e3dda5c0..df0a6450d 100644 --- a/lib/libimhex/source/helpers/file.cpp +++ b/lib/libimhex/source/helpers/file.cpp @@ -69,7 +69,7 @@ namespace hex::fs { std::vector File::readBytes(size_t numBytes) { if (!isValid()) return {}; - auto size = numBytes ?: getSize(); + auto size = numBytes == 0 ? getSize() : numBytes; if (size == 0) return {}; std::vector bytes(size); diff --git a/lib/libimhex/source/helpers/magic.cpp b/lib/libimhex/source/helpers/magic.cpp index 1a11315ca..101908669 100644 --- a/lib/libimhex/source/helpers/magic.cpp +++ b/lib/libimhex/source/helpers/magic.cpp @@ -57,8 +57,10 @@ namespace hex::magic { magic_t ctx = magic_open(MAGIC_NONE); ON_SCOPE_EXIT { magic_close(ctx); }; - if (magic_load(ctx, magicFiles->c_str()) == 0) - return magic_buffer(ctx, data.data(), data.size()) ?: ""; + if (magic_load(ctx, magicFiles->c_str()) == 0) { + if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr) + return result; + } } return ""; @@ -78,8 +80,10 @@ namespace hex::magic { magic_t ctx = magic_open(MAGIC_MIME_TYPE); ON_SCOPE_EXIT { magic_close(ctx); }; - if (magic_load(ctx, magicFiles->c_str()) == 0) - return magic_buffer(ctx, data.data(), data.size()) ?: ""; + if (magic_load(ctx, magicFiles->c_str()) == 0) { + if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr) + return result; + } } return ""; diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 543aa442a..a05a83743 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -196,10 +196,11 @@ namespace hex { return "Space"; case 127: return "DEL"; - case 128 ... 255: - return " "; default: - return std::string() + static_cast(c); + if (c >= 128) + return " "; + else + return std::string() + static_cast(c); } } diff --git a/plugins/builtin/source/content/data_visualizers.cpp b/plugins/builtin/source/content/data_visualizers.cpp index 5e868cd0f..1bc305b68 100644 --- a/plugins/builtin/source/content/data_visualizers.cpp +++ b/plugins/builtin/source/content/data_visualizers.cpp @@ -91,11 +91,11 @@ namespace hex::plugin::builtin { case 0xFF: ImGui::TextDisabled("##"); break; - case ' ' ... '~': - ImGui::Text(".%c", c); - break; default: - ImGui::Text(getFormatString(upperCase), c); + if (c >= ' ' && c <= '~') + ImGui::Text(".%c", c); + else + ImGui::Text(getFormatString(upperCase), c); break; } } diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 05dfb8b0a..c26c13a31 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -415,11 +415,22 @@ namespace hex::plugin::builtin { using enum SearchSettings::Value::Type; using enum Occurrence::DecodeType; - case U8 ... U64: return Unsigned; - case I8 ... I64: return Signed; - case F32: return Float; - case F64: return Double; - default: return Binary; + case U8: + case U16: + case U32: + case U64: + return Unsigned; + case I8: + case I16: + case I32: + case I64: + return Signed; + case F32: + return Float; + case F64: + return Double; + default: + return Binary; } }(); diff --git a/plugins/builtin/source/content/views/view_yara.cpp b/plugins/builtin/source/content/views/view_yara.cpp index fde275dac..1d14dabc9 100644 --- a/plugins/builtin/source/content/views/view_yara.cpp +++ b/plugins/builtin/source/content/views/view_yara.cpp @@ -6,7 +6,12 @@ #include #include +// 's RE type has a zero-sized array, which is not allowed in ISO C++. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" #include +#pragma GCC diagnostic pop + #include #include diff --git a/tests/algorithms/CMakeLists.txt b/tests/algorithms/CMakeLists.txt index 540dea37b..76681489a 100644 --- a/tests/algorithms/CMakeLists.txt +++ b/tests/algorithms/CMakeLists.txt @@ -37,7 +37,7 @@ add_executable(${PROJECT_NAME} # ---- No need to change anything from here downwards unless you know what you're doing ---- # target_include_directories(${PROJECT_NAME} PRIVATE include) -target_link_libraries(${PROJECT_NAME} libimhex tests_common) +target_link_libraries(${PROJECT_NAME} PRIVATE libimhex tests_common ${FMT_LIBRARIES}) set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 0b25d5123..7732e00b5 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -6,4 +6,4 @@ add_library(tests_common STATIC source/main.cpp ) target_include_directories(tests_common PUBLIC include) -target_link_libraries(tests_common PUBLIC libimhex) \ No newline at end of file +target_link_libraries(tests_common PUBLIC libimhex ${FMT_LIBRARIES}) \ No newline at end of file diff --git a/tests/helpers/CMakeLists.txt b/tests/helpers/CMakeLists.txt index 344044359..64826ad42 100644 --- a/tests/helpers/CMakeLists.txt +++ b/tests/helpers/CMakeLists.txt @@ -37,7 +37,7 @@ add_executable(${PROJECT_NAME} # ---- No need to change anything from here downwards unless you know what you're doing ---- # target_include_directories(${PROJECT_NAME} PRIVATE include) -target_link_libraries(${PROJECT_NAME} libimhex tests_common) +target_link_libraries(${PROJECT_NAME} PRIVATE libimhex tests_common ${FMT_LIBRARIES}) set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})