diff options
author | Xanadu <none@none> | 2010-10-17 20:35:11 +0200 |
---|---|---|
committer | Xanadu <none@none> | 2010-10-17 20:35:11 +0200 |
commit | 1e101ed785427c362ba8a7ff9f645cc4dcd9ff22 (patch) | |
tree | 7446b765cda673af6b73423b29069b69a2be82e8 /src/server/shared/Utilities/Util.cpp | |
parent | c0faed2251dff3814fe60e1a8ba86a046e48f707 (diff) |
Core/Utils: Fixed some unsafe calls to utf8 translation functions.
--HG--
branch : trunk
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) |