diff options
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rwxr-xr-x | src/server/shared/Utilities/Util.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index 7b2fdaf682f..6afbe92c0b7 100755 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -307,7 +307,8 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr) size_t len = utf8::distance(utf8str.c_str(),utf8str.c_str()+utf8str.size()); wstr.resize(len); - utf8::utf8to16(utf8str.c_str(),utf8str.c_str()+utf8str.size(),&wstr[0]); + if (len) + utf8::utf8to16(utf8str.c_str(),utf8str.c_str()+utf8str.size(),&wstr[0]); } catch(std::exception) { @@ -325,8 +326,11 @@ bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str) std::string utf8str2; utf8str2.resize(size*4); // allocate for most long case - char* oend = utf8::utf16to8(wstr,wstr+size,&utf8str2[0]); - utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail + if (size) + { + char* oend = utf8::utf16to8(wstr,wstr+size,&utf8str2[0]); + utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail + } utf8str = utf8str2; } catch(std::exception) @@ -345,8 +349,11 @@ bool WStrToUtf8(std::wstring wstr, std::string& utf8str) std::string utf8str2; utf8str2.resize(wstr.size()*4); // allocate for most long case - char* oend = utf8::utf16to8(wstr.c_str(),wstr.c_str()+wstr.size(),&utf8str2[0]); - utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail + if (wstr.size()) + { + char* oend = utf8::utf16to8(wstr.c_str(),wstr.c_str()+wstr.size(),&utf8str2[0]); + utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail + } utf8str = utf8str2; } catch(std::exception) |