From 50a531c977ea1ca507d1b4aa495f18a3b6d65d98 Mon Sep 17 00:00:00 2001 From: Elliu <elliu@hashi.re> Date: Sat, 2 Sep 2023 13:18:16 +0200 Subject: [PATCH] BUILD: silence warnings: add -Wno-unsafe-buffer-usage for Clang --- CMakeLists.txt | 5 +++++ src/Lib/Log.cc | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea0c5bac..f2b4bdf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,11 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") -Wno-global-constructors -Wno-exit-time-destructors ) + if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 16) + target_compile_options(Vivy PRIVATE + -Wno-unsafe-buffer-usage + ) + endif() elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") target_compile_options(Vivy PRIVATE -Wno-subobject-linkage # Kubat: Some proglems here, it seems they diff --git a/src/Lib/Log.cc b/src/Lib/Log.cc index 4cede87d..cf7a9485 100644 --- a/src/Lib/Log.cc +++ b/src/Lib/Log.cc @@ -277,12 +277,14 @@ LogMessage::operator<<(const std::string_view strv) noexcept LogMessage & LogMessage::operator<<(const char *str) noexcept { - const std::size_t length = strlen(str); - for (std::size_t i = 0; (i < length) && (indexInArray < messageBufferLength - 1); - ++i, ++indexInArray) { - textBuffer[indexInArray] = str[i]; + if (str){ + const std::size_t length = strlen(str); + for (std::size_t i = 0; (i < length) && (indexInArray < messageBufferLength - 1); + ++i, ++indexInArray) { + textBuffer[indexInArray] = str[i]; + } + textBuffer[indexInArray] = '\0'; } - textBuffer[indexInArray] = '\0'; return *this; } -- GitLab