Fix `charToWideChar` in FreeTypeGX

This commit is contained in:
Maschell 2020-08-13 14:13:01 +02:00
parent d89093de78
commit e6b07f9e67
1 changed files with 8 additions and 7 deletions

View File

@ -70,17 +70,18 @@ FreeTypeGX::~FreeTypeGX() {
wchar_t *FreeTypeGX::charToWideChar(const char *strChar) {
if (!strChar) { return NULL; }
wchar_t *strWChar = new(std::nothrow) wchar_t[strlen(strChar) + 1];
size_t len = strlen(strChar) + 1;
wchar_t *strWChar = new(std::nothrow) wchar_t[len];
if (!strWChar) { return NULL; }
int32_t bt = mbstowcs(strWChar, strChar, strlen(strChar));
if (bt > 0) {
strWChar[bt] = 0;
return strWChar;
size_t bt = mbstowcs(strWChar, strChar, len);
if (bt == (size_t) -1) {
return NULL;
}
wchar_t *tempDest = strWChar;
while ((*tempDest++ = *strChar++));
if (bt < --len) {
strWChar[bt] = 0;
}
return strWChar;
}