From dcc7bd16d4e7d24c61fe23690c7e9ba8092748c3 Mon Sep 17 00:00:00 2001 From: hanaxars <156359933+hanaxars@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:24:36 +0300 Subject: [PATCH] Update rcore_desktop_glfw.c Fix for #4695 --- src/platforms/rcore_desktop_glfw.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index dba821dd..786a5099 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1652,7 +1652,11 @@ int InitPlatform(void) // Retrieve gamepad names for (int i = 0; i < MAX_GAMEPADS; i++) { - if (glfwJoystickPresent(i)) strcpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i)); + if (glfwJoystickPresent(i)) + { + strncpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i), sizeof(CORE.Input.Gamepad.name[i]) - 1); + CORE.Input.Gamepad.name[i][sizeof(CORE.Input.Gamepad.name[i]) - 1] = '\0'; + } } //---------------------------------------------------------------------------- @@ -1915,11 +1919,12 @@ static void JoystickCallback(int jid, int event) { if (event == GLFW_CONNECTED) { - strcpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid)); + strncpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid), sizeof(CORE.Input.Gamepad.name[jid]) - 1); + CORE.Input.Gamepad.name[jid][sizeof(CORE.Input.Gamepad.name[jid]) - 1] = '\0'; } else if (event == GLFW_DISCONNECTED) { - memset(CORE.Input.Gamepad.name[jid], 0, 64); + memset(CORE.Input.Gamepad.name[jid], 0, sizeof(CORE.Input.Gamepad.name[jid])); } }