From 431d29b6a12c7edeb60e8409c72f69237225f06e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 5 Sep 2023 23:54:22 +0200 Subject: [PATCH] - don't run string conversions on empty strings. std::string complains about this case --- source/CMakeLists.txt | 4 ++-- .../common/filesystem/source/fs_findfile.cpp | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ba26a02ca..ea4d3f18e 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -383,12 +383,12 @@ else() message( SEND_ERROR "Could not find libvpx" ) endif() -#if (TARGET WebP::webp) +if (TARGET WebP::webp) list( APPEND PROJECT_LIBRARIES WebP::webp WebP::webpdemux WebP::libwebpmux ) if (TARGET WebP::webpdecoder) list( APPEND PROJECT_LIBRARIES WebP::webpdecoder) endif() -#endif() +endif() include_directories( SYSTEM "${ZLIB_INCLUDE_DIR}" "${ZMUSIC_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${TESS_INCLUDE_DIR}" "${DRPC_INCLUDE_DIR}" ) diff --git a/source/common/filesystem/source/fs_findfile.cpp b/source/common/filesystem/source/fs_findfile.cpp index 689a5d644..06d9b69f1 100644 --- a/source/common/filesystem/source/fs_findfile.cpp +++ b/source/common/filesystem/source/fs_findfile.cpp @@ -202,20 +202,26 @@ static size_t FS_GetFileSize(findstate_t* handle, const char* pathname) std::wstring toWide(const char* str) { int len = (int)strlen(str); - int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, nullptr, 0); std::wstring wide; - wide.resize(size_needed); - MultiByteToWideChar(CP_UTF8, 0, str, len, &wide.front(), size_needed); + if (len > 0) + { + int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, nullptr, 0); + wide.resize(size_needed); + MultiByteToWideChar(CP_UTF8, 0, str, len, &wide.front(), size_needed); + } return wide; } static std::string toUtf8(const wchar_t* str) { auto len = wcslen(str); - int size_needed = WideCharToMultiByte(CP_UTF8, 0, str, (int)len, nullptr, 0, nullptr, nullptr); std::string utf8; - utf8.resize(size_needed); - WideCharToMultiByte(CP_UTF8, 0, str, (int)len, &utf8.front(), size_needed, nullptr, nullptr); + if (len > 0) + { + int size_needed = WideCharToMultiByte(CP_UTF8, 0, str, (int)len, nullptr, 0, nullptr, nullptr); + utf8.resize(size_needed); + WideCharToMultiByte(CP_UTF8, 0, str, (int)len, &utf8.front(), size_needed, nullptr, nullptr); + } return utf8; }