aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Util.cpp
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2019-01-12 12:05:48 +0100
committerjackpoz <giacomopoz@gmail.com>2019-01-12 12:05:48 +0100
commitbdb7e6e5e81e0d9376c9c803bae9da470b02d8cd (patch)
tree574451b8c308d851b3707ff54d3b29b0ba296593 /src/common/Utilities/Util.cpp
parentfb28083b3b2966952b1227f6585b48fcc70dbe7a (diff)
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.
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r--src/common/Utilities/Util.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index ad042ab216c..3735cca089f 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -260,9 +260,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;
}