From d1d35633c067ddd3acd04f813f5331088906bb77 Mon Sep 17 00:00:00 2001 From: Christophe Larchier Date: Tue, 3 Dec 2024 08:12:24 +0100 Subject: [PATCH] Address comment --- src/libcommon/utility/utility.cpp | 7 +++++++ src/libcommon/utility/utility.h | 5 +++++ src/libcommongui/logger.cpp | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libcommon/utility/utility.cpp b/src/libcommon/utility/utility.cpp index d6d0fee3a..c0b20d014 100644 --- a/src/libcommon/utility/utility.cpp +++ b/src/libcommon/utility/utility.cpp @@ -880,6 +880,13 @@ void CommonUtility::clearSignalFile(const AppType appType, const SignalCategory } } +#ifdef _WIN32 +std::string CommonUtility::toUnsafeStr(const SyncName &name) { + std::string unsafeName(name.begin(), name.end()); + return unsafeName; +} +#endif + #ifdef __APPLE__ bool CommonUtility::isLiteSyncExtEnabled() { QProcess *process = new QProcess(); diff --git a/src/libcommon/utility/utility.h b/src/libcommon/utility/utility.h index e2768cb57..ecd4c3615 100644 --- a/src/libcommon/utility/utility.h +++ b/src/libcommon/utility/utility.h @@ -118,6 +118,11 @@ struct COMMON_EXPORT CommonUtility { static void writeSignalFile(AppType appType, SignalType signalType) noexcept; static void clearSignalFile(AppType appType, SignalCategory signalCategory, SignalType &signalType) noexcept; +#ifdef _WIN32 + // Converts a std::wstring to std::string assuming that it contains only mono byte chars + static std::string toUnsafeStr(const SyncName &name); +#endif + private: static void extractIntFromStrVersion(const std::string &version, std::vector &tabVersion); }; diff --git a/src/libcommongui/logger.cpp b/src/libcommongui/logger.cpp index 6757ba572..4a6caaa75 100644 --- a/src/libcommongui/logger.cpp +++ b/src/libcommongui/logger.cpp @@ -54,8 +54,8 @@ static void kdriveLogCatcher(QtMsgType type, const QMessageLogContext &ctx, cons } #ifdef _WIN32 // For performance purposes, assume that the file name contains only mono byte chars - std::string fileNameStr(fileName.begin(), fileName.end()); - const char *fileNamePtr = fileNameStr.c_str(); + std::string unsafeFileName(CommonUtility::toUnsafeStr(fileName)); + const char *fileNamePtr = unsafeFileName.c_str(); #else const char *fileNamePtr = fileName.c_str(); #endif