- don't run string conversions on empty strings.

std::string complains about this case
This commit is contained in:
Christoph Oelckers 2023-09-05 23:54:22 +02:00
parent 4e53f3bd81
commit 431d29b6a1
2 changed files with 14 additions and 8 deletions

View file

@ -383,12 +383,12 @@ else()
message( SEND_ERROR "Could not find libvpx" ) message( SEND_ERROR "Could not find libvpx" )
endif() endif()
#if (TARGET WebP::webp) if (TARGET WebP::webp)
list( APPEND PROJECT_LIBRARIES WebP::webp WebP::webpdemux WebP::libwebpmux ) list( APPEND PROJECT_LIBRARIES WebP::webp WebP::webpdemux WebP::libwebpmux )
if (TARGET WebP::webpdecoder) if (TARGET WebP::webpdecoder)
list( APPEND PROJECT_LIBRARIES WebP::webpdecoder) list( APPEND PROJECT_LIBRARIES WebP::webpdecoder)
endif() 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}" ) include_directories( SYSTEM "${ZLIB_INCLUDE_DIR}" "${ZMUSIC_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${TESS_INCLUDE_DIR}" "${DRPC_INCLUDE_DIR}" )

View file

@ -202,20 +202,26 @@ static size_t FS_GetFileSize(findstate_t* handle, const char* pathname)
std::wstring toWide(const char* str) std::wstring toWide(const char* str)
{ {
int len = (int)strlen(str); int len = (int)strlen(str);
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, nullptr, 0);
std::wstring wide; std::wstring wide;
wide.resize(size_needed); if (len > 0)
MultiByteToWideChar(CP_UTF8, 0, str, len, &wide.front(), size_needed); {
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; return wide;
} }
static std::string toUtf8(const wchar_t* str) static std::string toUtf8(const wchar_t* str)
{ {
auto len = wcslen(str); auto len = wcslen(str);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, str, (int)len, nullptr, 0, nullptr, nullptr);
std::string utf8; std::string utf8;
utf8.resize(size_needed); if (len > 0)
WideCharToMultiByte(CP_UTF8, 0, str, (int)len, &utf8.front(), size_needed, nullptr, nullptr); {
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; return utf8;
} }