diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2018-11-18 07:22:28 -0600 |
|---|---|---|
| committer | Pierre Bourdon <delroth@gmail.com> | 2018-11-22 06:50:11 +0100 |
| commit | fae368d2eec9cd55f4f7305ca3c193b58b19aa67 (patch) | |
| tree | 58a4f3b1e20de762f3130d2b6ed142ba16068076 /Source/Core/Common/StringUtil.cpp | |
| parent | 0c6d67723322522e03b6ec6eb4fe8c8b3ad5182f (diff) | |
Fix spurious error logs for conversions of empty strings on Windows.
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index c2a5a62b2d..2e79fe9176 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -471,20 +471,25 @@ std::wstring CPToUTF16(u32 code_page, const std::string& input) std::string UTF16ToCP(u32 code_page, const std::wstring& input) { - auto const size = WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()), - nullptr, 0, nullptr, false); - std::string output; - output.resize(size); - if (size == 0 || - size != WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()), - &output[0], static_cast<int>(output.size()), nullptr, false)) + if (0 != input.size()) { - const DWORD error_code = GetLastError(); - ERROR_LOG(COMMON, "WideCharToMultiByte Error in String '%s': %lu", input.c_str(), error_code); - output.clear(); + // "If cchWideChar [input buffer size] is set to 0, the function fails." -MSDN + auto const size = WideCharToMultiByte( + code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, false); + + output.resize(size); + + if (size != WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()), + &output[0], static_cast<int>(output.size()), nullptr, false)) + { + const DWORD error_code = GetLastError(); + ERROR_LOG(COMMON, "WideCharToMultiByte Error in String '%s': %lu", input.c_str(), error_code); + output.clear(); + } } + return output; } |
