From 8640358748782a22ab098df938c53a3313d3c5e1 Mon Sep 17 00:00:00 2001 From: Luc Guyot Date: Thu, 19 Sep 2024 13:48:16 +0200 Subject: [PATCH] Enables new compilation warnings with a view to sanitize code --- CMakeLists.txt | 2 ++ src/3rdparty/keychain/src/keychain_mac.cpp | 35 +++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02e6de132..adc5e4073 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,8 @@ if (NOT DEFINED APPLICATION_ICON_NAME) set(APPLICATION_ICON_NAME "${APPLICATION_SHORTNAME}") endif () +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -Wsign-conversion -Weffc++ -Wimplicit-fallthrough -Wformat=2") + if (WIN32) add_definitions(-D__USE_MINGW_ANSI_STDIO=1) add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) diff --git a/src/3rdparty/keychain/src/keychain_mac.cpp b/src/3rdparty/keychain/src/keychain_mac.cpp index 965334820..3e7b43445 100644 --- a/src/3rdparty/keychain/src/keychain_mac.cpp +++ b/src/3rdparty/keychain/src/keychain_mac.cpp @@ -31,7 +31,7 @@ namespace { -const SecKeychainRef defaultUserKeychain = NULL; // NULL means 'default' +const SecKeychainRef defaultUserKeychain = NULL; // NULL means 'default' /*! \brief Converts a CFString to a std::string * @@ -44,11 +44,11 @@ std::string CFStringToStdString(const CFStringRef cfstring) { return std::string(ccstr); } - auto utf16Pairs = CFStringGetLength(cfstring); - auto maxUtf8Bytes = CFStringGetMaximumSizeForEncoding(utf16Pairs, kCFStringEncodingUTF8); + const auto utf16Pairs = CFStringGetLength(cfstring); + const auto maxUtf8Bytes = CFStringGetMaximumSizeForEncoding(utf16Pairs, kCFStringEncodingUTF8); - std::vector cstr(maxUtf8Bytes, '\0'); - auto result = CFStringGetCString(cfstring, cstr.data(), cstr.size(), kCFStringEncodingUTF8); + std::vector cstr(static_cast(maxUtf8Bytes), '\0'); + const auto result = CFStringGetCString(cfstring, cstr.data(), static_cast(cstr.size()), kCFStringEncodingUTF8); return result ? std::string(cstr.data()) : std::string(); } @@ -90,9 +90,9 @@ void updateError(keychain::Error &err, OSStatus status) { break; // potential errors in case the user needs to unlock the keychain first - case errSecUserCanceled: // user pressed the Cancel button - case errSecAuthFailed: // too many failed password attempts - case errSecInteractionRequired: // user interaction required but not allowed + case errSecUserCanceled: // user pressed the Cancel button + case errSecAuthFailed: // too many failed password attempts + case errSecInteractionRequired: // user interaction required but not allowed err.type = keychain::ErrorType::AccessDenied; break; @@ -110,8 +110,8 @@ OSStatus modifyPassword(const std::string &serviceName, const std::string &user, SecKeychainItemRef item = NULL; OSStatus status = SecKeychainFindGenericPassword(defaultUserKeychain, static_cast(serviceName.length()), serviceName.data(), static_cast(user.length()), user.data(), - NULL, // unused output parameter - NULL, // unused output parameter + NULL, // unused output parameter + NULL, // unused output parameter &item); if (status == errSecSuccess) { @@ -125,7 +125,7 @@ OSStatus modifyPassword(const std::string &serviceName, const std::string &user, return status; } -} // namespace +} // namespace namespace keychain { @@ -134,9 +134,10 @@ void setPassword(const std::string &package, const std::string &service, const s err = Error{}; const auto serviceName = makeServiceName(package, service); - OSStatus status = SecKeychainAddGenericPassword( - defaultUserKeychain, static_cast(serviceName.length()), serviceName.data(), static_cast(user.length()), - user.data(), static_cast(password.length()), password.data(), NULL /* unused output parameter */); + OSStatus status = + SecKeychainAddGenericPassword(defaultUserKeychain, static_cast(serviceName.length()), serviceName.data(), + static_cast(user.length()), user.data(), static_cast(password.length()), + password.data(), NULL /* unused output parameter */); if (status == errSecDuplicateItem) { // password exists -- override @@ -177,8 +178,8 @@ void deletePassword(const std::string &package, const std::string &service, cons OSStatus status = SecKeychainFindGenericPassword(defaultUserKeychain, static_cast(serviceName.length()), serviceName.data(), static_cast(user.length()), user.data(), - NULL, // unused output parameter - NULL, // unused output parameter + NULL, // unused output parameter + NULL, // unused output parameter &item); if (status != errSecSuccess) { @@ -195,4 +196,4 @@ void deletePassword(const std::string &package, const std::string &service, cons } } -} // namespace keychain +} // namespace keychain