Core/Utils: Handle UTF-8 conversion errors
Replace the output string when a UTF-8 conversion error happen with an error message instead of using an empty string, swallowing any message that the caller wanted to log.
This commit is contained in:
1 parent
cd3fa07389
commit
8714c2be57
1 file changed
+16
-2
@@ -293,9 +293,23 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
|
||||
}
|
||||
catch (std::exception)
|
||||
{
|
||||
if (wsize > 0)
|
||||
// Replace the converted string with an error message if there is enough space
|
||||
// Otherwise just return an empty string
|
||||
wchar_t const* errorMessage = L"An error occurred converting string from UTF-8 to WStr";
|
||||
size_t errorMessageLength = wcslen(errorMessage);
|
||||
if (wsize >= errorMessageLength)
|
||||
{
|
||||
wcscpy(wstr, errorMessage);
|
||||
wsize = wcslen(wstr);
|
||||
}
|
||||
else if (wsize > 0)
|
||||
{
|
||||
wstr[0] = L'\0';
|
||||
wsize = 0;
|
||||
wsize = 0;
|
||||
}
|
||||
else
|
||||
wsize = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user