From 24bb9368692629cfec14925bf79e05db31ec5685 Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Thu, 3 Oct 2024 21:40:09 +0200 Subject: [PATCH 1/5] appFs - fix sign conversion --- src/appFs/appFs.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/appFs/appFs.cpp b/src/appFs/appFs.cpp index ecc1927..740cc9c 100644 --- a/src/appFs/appFs.cpp +++ b/src/appFs/appFs.cpp @@ -32,7 +32,8 @@ static off_t getMaxFileSize(const std::shared_ptr& file) } constexpr double requiredBlockEmptyCapacityMultiplier = 0.5; - constexpr size_t requiredCapacity = blockSize * requiredBlockEmptyCapacityMultiplier; + constexpr auto requiredCapacity = static_cast( + static_cast(blockSize) * requiredBlockEmptyCapacityMultiplier); const size_t contentSize = fileContentToString(file).size(); const size_t blockSizeMultiplier = (contentSize + requiredCapacity) / blockSize + 1; @@ -217,12 +218,14 @@ static int readFile( cacheBuffer = fileContentToString(file); } - if (static_cast(offset) >= cacheBuffer.size()) { + const auto uOffset = static_cast(offset); + + if (uOffset >= cacheBuffer.size()) { return 0; } - const size_t length = std::min(size, cacheBuffer.size() - offset); - std::memcpy(buffer, cacheBuffer.c_str() + offset, length); + const size_t length = std::min(size, cacheBuffer.size() - uOffset); + std::memcpy(buffer, cacheBuffer.c_str() + uOffset, length); return static_cast(length); } From 3aa0180a4e294c0f3ad538afd9e8afd7cdd5418b Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Thu, 3 Oct 2024 22:31:58 +0200 Subject: [PATCH 2/5] cmake - googletest - remove -Wsign-conversion cxx flag --- cmake/googletest.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/googletest.cmake b/cmake/googletest.cmake index 0f2aa4f..b9ca222 100644 --- a/cmake/googletest.cmake +++ b/cmake/googletest.cmake @@ -12,4 +12,10 @@ FetchContent_Declare( GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0 ) + +# Library does not compile with -Wsign-conversion that we use in builds +string(REPLACE "-Wsign-conversion " " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ") +string(REPLACE "-Wsign-conversion " " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ") +string(REPLACE "-Wsign-conversion " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") + FetchContent_MakeAvailable(googletest) From e6f31f446851bf2457ba294e3a468f6581dc9ae9 Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Thu, 3 Oct 2024 21:40:39 +0200 Subject: [PATCH 3/5] cmake - add CXX flags Added flags: -Wunused -Wconversion -Wsign-conversion --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 465d57a..a7f14d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wunused -Wconversion -Wsign-conversion") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Werror") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb3") From ef164304d16946d903f7b4eb4fc47b0a1710024a Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Thu, 3 Oct 2024 21:47:04 +0200 Subject: [PATCH 4/5] cmake - remove unnecessary lines --- CMakeLists.txt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7f14d2..3beba24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,12 @@ project(telemetry VERSION ${VERSION}) include(cmake/build_type.cmake) include(cmake/installation.cmake) +include(cmake/dependencies.cmake) -option(TELEMETRY_BUILD_SHARED "Build shared library" ON) -option(TELEMETRY_PACKAGE_BUILDER "Enable RPM package builder (make rpm)" ON) -option(TELEMETRY_INSTALL_TARGETS "Generate the install target" ON) -option(TELEMETRY_ENABLE_TESTS "Build Unit tests (make test)" OFF) +option(TELEMETRY_BUILD_SHARED "Build shared library" ON) +option(TELEMETRY_PACKAGE_BUILDER "Enable RPM package builder (make rpm)" ON) +option(TELEMETRY_INSTALL_TARGETS "Generate the install target" ON) +option(TELEMETRY_ENABLE_TESTS "Build Unit tests (make test)" OFF) option(TELEMETRY_ENABLE_DOC_DOXYGEN "Enable build of code documentation" OFF) set(CMAKE_CXX_STANDARD 17) @@ -25,15 +26,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wunused -Wconve set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Werror") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb3") -# This option ensures that standard include header paths are explicitly added -# to the generated compile_commands.json file. -# clang-tidy doesn't seem to find standard include headers otherwise. -if (CMAKE_EXPORT_COMPILE_COMMANDS) - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) -endif() - -include(cmake/dependencies.cmake) - if (TELEMETRY_ENABLE_TESTS) include(cmake/googletest.cmake) include(GoogleTest) From c074b4bc77eae5e2b470f048d80dcf6d758bc328 Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Thu, 3 Oct 2024 21:47:32 +0200 Subject: [PATCH 5/5] cmake - increase minimal required cmake version to 3.18 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3beba24..4815d51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.18) set(VERSION_MAJOR 0) set(VERSION_MINOR 3)