From e049594552125be1735282c974b6d8a5344b8378 Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Sun, 26 Apr 2020 14:43:01 +0200 Subject: [PATCH 1/2] Fix #3 Signed-off-by: Thomas Rohloff --- source/gui/FreeTypeGX.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/gui/FreeTypeGX.cpp b/source/gui/FreeTypeGX.cpp index bab0836..96c8187 100644 --- a/source/gui/FreeTypeGX.cpp +++ b/source/gui/FreeTypeGX.cpp @@ -70,11 +70,15 @@ 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) { + size_t bt = mbstowcs(strWChar, strChar, len); + if (bt == (size_t)-1) + return NULL; + + if (bt < --len) { strWChar[bt] = 0; return strWChar; } @@ -130,6 +134,7 @@ char *FreeTypeGX::wideCharToUTF8(const wchar_t* strChar) { pOut[n++] = (char)((wc & 0x3F) | 0x80); } } + pOut[n] = '\0'; return pOut; } From 66794338cb469fd570f54d68409edbe45ef66df0 Mon Sep 17 00:00:00 2001 From: Thomas Rohloff Date: Sun, 26 Apr 2020 15:06:34 +0200 Subject: [PATCH 2/2] Remove useless codes Signed-off-by: Thomas Rohloff --- source/gui/FreeTypeGX.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/source/gui/FreeTypeGX.cpp b/source/gui/FreeTypeGX.cpp index 96c8187..613a2b6 100644 --- a/source/gui/FreeTypeGX.cpp +++ b/source/gui/FreeTypeGX.cpp @@ -78,14 +78,8 @@ wchar_t* FreeTypeGX::charToWideChar(const char* strChar) { if (bt == (size_t)-1) return NULL; - if (bt < --len) { + if (bt < --len) strWChar[bt] = 0; - return strWChar; - } - - wchar_t *tempDest = strWChar; - while ((*tempDest++ = *strChar++)) - ; return strWChar; }