1
0
mirror of synced 2024-11-28 09:30:51 +01:00

build: Build everything using -Wpedantic

This commit is contained in:
WerWolv 2023-01-04 14:03:09 +01:00
parent 496b0ec41d
commit f7dd28002e
12 changed files with 56 additions and 35 deletions

View File

@ -383,7 +383,7 @@ function(downloadImHexPatternsFiles dest)
endfunction() endfunction()
macro(setupCompilerWarnings target) 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(IMHEX_C_FLAGS "${IMHEX_COMMON_FLAGS} -Wno-restrict -Wno-stringop-overread -Wno-stringop-overflow")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IMHEX_C_FLAGS}") 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(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) add_subdirectory(${EXTERN_LIBS_FOLDER}/imgui)
set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE ON)

@ -1 +1 @@
Subproject commit fb427b82a99076fdc3babaf0e2f5cb4717dac835 Subproject commit 4dec3adf6e2a8369569d64a6fe2c46b7c09f5943

View File

@ -95,23 +95,24 @@ set(LIBYARA_MODULES
${LIBYARA_SOURCE_PATH}/modules/time/time.c ${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) 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}) add_library(libyara STATIC ${LIBYARA_SOURCE} ${LIBYARA_INCLUDES} ${LIBYARA_MODULES})
set_property(TARGET libyara PROPERTY POSITION_INDEPENDENT_CODE ON) 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( target_include_directories(
libyara libyara
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/yara> $<BUILD_INTERFACE:${LIBYARA_SOURCE_PATH}/include> $<INSTALL_INTERFACE:include> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/yara> $<BUILD_INTERFACE:${LIBYARA_SOURCE_PATH}/include> $<INSTALL_INTERFACE:include>

View File

@ -69,7 +69,7 @@ namespace hex::fs {
std::vector<u8> File::readBytes(size_t numBytes) { std::vector<u8> File::readBytes(size_t numBytes) {
if (!isValid()) return {}; if (!isValid()) return {};
auto size = numBytes ?: getSize(); auto size = numBytes == 0 ? getSize() : numBytes;
if (size == 0) return {}; if (size == 0) return {};
std::vector<u8> bytes(size); std::vector<u8> bytes(size);

View File

@ -57,8 +57,10 @@ namespace hex::magic {
magic_t ctx = magic_open(MAGIC_NONE); magic_t ctx = magic_open(MAGIC_NONE);
ON_SCOPE_EXIT { magic_close(ctx); }; ON_SCOPE_EXIT { magic_close(ctx); };
if (magic_load(ctx, magicFiles->c_str()) == 0) if (magic_load(ctx, magicFiles->c_str()) == 0) {
return magic_buffer(ctx, data.data(), data.size()) ?: ""; if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr)
return result;
}
} }
return ""; return "";
@ -78,8 +80,10 @@ namespace hex::magic {
magic_t ctx = magic_open(MAGIC_MIME_TYPE); magic_t ctx = magic_open(MAGIC_MIME_TYPE);
ON_SCOPE_EXIT { magic_close(ctx); }; ON_SCOPE_EXIT { magic_close(ctx); };
if (magic_load(ctx, magicFiles->c_str()) == 0) if (magic_load(ctx, magicFiles->c_str()) == 0) {
return magic_buffer(ctx, data.data(), data.size()) ?: ""; if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr)
return result;
}
} }
return ""; return "";

View File

@ -196,10 +196,11 @@ namespace hex {
return "Space"; return "Space";
case 127: case 127:
return "DEL"; return "DEL";
case 128 ... 255:
return " ";
default: default:
return std::string() + static_cast<char>(c); if (c >= 128)
return " ";
else
return std::string() + static_cast<char>(c);
} }
} }

View File

@ -91,11 +91,11 @@ namespace hex::plugin::builtin {
case 0xFF: case 0xFF:
ImGui::TextDisabled("##"); ImGui::TextDisabled("##");
break; break;
case ' ' ... '~':
ImGui::Text(".%c", c);
break;
default: default:
ImGui::Text(getFormatString(upperCase), c); if (c >= ' ' && c <= '~')
ImGui::Text(".%c", c);
else
ImGui::Text(getFormatString(upperCase), c);
break; break;
} }
} }

View File

@ -415,11 +415,22 @@ namespace hex::plugin::builtin {
using enum SearchSettings::Value::Type; using enum SearchSettings::Value::Type;
using enum Occurrence::DecodeType; using enum Occurrence::DecodeType;
case U8 ... U64: return Unsigned; case U8:
case I8 ... I64: return Signed; case U16:
case F32: return Float; case U32:
case F64: return Double; case U64:
default: return Binary; return Unsigned;
case I8:
case I16:
case I32:
case I64:
return Signed;
case F32:
return Float;
case F64:
return Double;
default:
return Binary;
} }
}(); }();

View File

@ -6,7 +6,12 @@
#include <hex/helpers/file.hpp> #include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
// <yara/types.h>'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 <yara.h> #include <yara.h>
#pragma GCC diagnostic pop
#include <filesystem> #include <filesystem>
#include <thread> #include <thread>

View File

@ -37,7 +37,7 @@ add_executable(${PROJECT_NAME}
# ---- No need to change anything from here downwards unless you know what you're doing ---- # # ---- No need to change anything from here downwards unless you know what you're doing ---- #
target_include_directories(${PROJECT_NAME} PRIVATE include) 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}) set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

View File

@ -6,4 +6,4 @@ add_library(tests_common STATIC
source/main.cpp source/main.cpp
) )
target_include_directories(tests_common PUBLIC include) target_include_directories(tests_common PUBLIC include)
target_link_libraries(tests_common PUBLIC libimhex) target_link_libraries(tests_common PUBLIC libimhex ${FMT_LIBRARIES})

View File

@ -37,7 +37,7 @@ add_executable(${PROJECT_NAME}
# ---- No need to change anything from here downwards unless you know what you're doing ---- # # ---- No need to change anything from here downwards unless you know what you're doing ---- #
target_include_directories(${PROJECT_NAME} PRIVATE include) 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}) set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})