From 3c44229af809cdec2914f2aab9af5176b741e4f5 Mon Sep 17 00:00:00 2001 From: Bayemite Date: Thu, 3 Jun 2021 22:02:24 +1000 Subject: [PATCH] fix C89 forbidden mixed declarations --- include/GLFW/glfw3.h | 4 ++-- src/win32_window.c | 22 ++++++++++++++-------- src/x11_window.c | 16 ++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index a971c6dc..97e69e19 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -2907,7 +2907,7 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value); * GLFW_PLATFORM_ERROR. * * @remark Do not forget to free the returned char* when you are done with it. - * + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_title @@ -2935,7 +2935,7 @@ GLFWAPI char* glfwGetWindowTitle(GLFWwindow* window); * * @sa @ref window_title * @sa @ref glfwGetWindowTitle - * + * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * diff --git a/src/win32_window.c b/src/win32_window.c index 0fa02e22..9aa106cc 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1464,11 +1464,14 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) char* _glfwPlatformGetWindowTitle(_GLFWwindow* window) { - int count = GetWindowTextLengthW(window->win32.handle); + int count; + SetLastError(0); + + count = GetWindowTextLengthW(window->win32.handle); if(count == 0) { - SetLastError(0); - int error = GetLastError(); + int error; + error = GetLastError(); if(error != 0) { @@ -1477,18 +1480,21 @@ char* _glfwPlatformGetWindowTitle(_GLFWwindow* window) } else return calloc(1, sizeof(char)); // single \0 - + } else { + WCHAR* wideTitle; + char* title; count += 1; // the \0 - WCHAR* wideTitle = calloc(count, sizeof(WCHAR)); + + wideTitle = calloc(count, sizeof(WCHAR)); GetWindowTextW(window->win32.handle, wideTitle, count); - - char* title = _glfwCreateUTF8FromWideStringWin32(wideTitle); + + title = _glfwCreateUTF8FromWideStringWin32(wideTitle); if(!title) return calloc(1, sizeof(char)); // single \0 - + return title; } } diff --git a/src/x11_window.c b/src/x11_window.c index 786ae2f9..e8968c17 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2084,7 +2084,7 @@ char* _glfwPlatformGetWindowTitle(_GLFWwindow* window) char* title; _glfwGrabErrorHandlerX11(); - + if (XGetWMName(_glfw.x11.display, window->x11.handle, &textProperty) == 0) { _glfwInputErrorX11(GLFW_PLATFORM_ERROR, "X11: Could not get window title"); @@ -2100,10 +2100,10 @@ char* _glfwPlatformGetWindowTitle(_GLFWwindow* window) _glfwInputErrorX11(GLFW_PLATFORM_ERROR, "X11: No memory to convert window title to UTF-8"); else if (ret == XLocaleNotSupported || ret == XConverterNotFound) _glfwInputErrorX11(GLFW_PLATFORM_ERROR, "X11: Cannot convert window title, unsupported locale"); - + if (textProperty.value != NULL) XFree(textProperty.value); - + return NULL; } @@ -2112,19 +2112,19 @@ char* _glfwPlatformGetWindowTitle(_GLFWwindow* window) _glfwReleaseErrorHandlerX11(); if (textProperty.value != NULL) - XFree(textProperty.value); + XFree(textProperty.value); if (charList != NULL) XFreeStringList(charList); - + return calloc(1, sizeof(char)); } - + title = _glfw_strdup(charList[0]); - + _glfwReleaseErrorHandlerX11(); if (textProperty.value != NULL) - XFree(textProperty.value); + XFree(textProperty.value); if (charList != NULL) XFreeStringList(charList);