fix(Core/Crash): Improved Utf8toWStr() function to prevent crashes (#2407)
This commit is contained in:
committed by
Stoabrogga
parent
77c97598f0
commit
c294dd3142
@@ -333,17 +333,14 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
|
|||||||
|
|
||||||
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
|
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
|
||||||
{
|
{
|
||||||
|
wstr.clear();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (size_t len = utf8::distance(utf8str.c_str(), utf8str.c_str()+utf8str.size()))
|
utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), std::back_inserter(wstr));
|
||||||
{
|
|
||||||
wstr.resize(len);
|
|
||||||
utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), &wstr[0]);
|
|
||||||
}
|
}
|
||||||
}
|
catch(std::exception const&)
|
||||||
catch(std::exception)
|
|
||||||
{
|
{
|
||||||
wstr = L"";
|
wstr.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user