Core/Utils: Fixed some unsafe calls to utf8 translation functions.

--HG--
branch : trunk
This commit is contained in:
Xanadu
2010-10-17 20:35:11 +02:00
parent c0faed2251
commit 1e101ed785

View File

@@ -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)