Win32: Fix text conversion size semantics

This commit is contained in:
Camilla Löwy 2017-09-13 17:47:49 +02:00
parent f8668c5a9f
commit 7f0d5e0a03

View File

@ -357,19 +357,19 @@ static HWND createHelperWindow(void)
WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source) WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source)
{ {
WCHAR* target; WCHAR* target;
int length; int count;
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); count = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
if (!length) if (!count)
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to convert string from UTF-8"); "Win32: Failed to convert string from UTF-8");
return NULL; return NULL;
} }
target = calloc(length, sizeof(WCHAR)); target = calloc(count, sizeof(WCHAR));
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length)) if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, count))
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to convert string from UTF-8"); "Win32: Failed to convert string from UTF-8");
@ -385,19 +385,19 @@ WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source)
char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source) char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source)
{ {
char* target; char* target;
int length; int size;
length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL); size = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
if (!length) if (!size)
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to convert string to UTF-8"); "Win32: Failed to convert string to UTF-8");
return NULL; return NULL;
} }
target = calloc(length, 1); target = calloc(size, 1);
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL)) if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL))
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to convert string to UTF-8"); "Win32: Failed to convert string to UTF-8");