Browse Source

Update rcore_desktop_glfw.c

Fix for #4695
pull/4697/head
hanaxars 12 hours ago
committed by GitHub
parent
commit
dcc7bd16d4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      src/platforms/rcore_desktop_glfw.c

+ 8
- 3
src/platforms/rcore_desktop_glfw.c View File

@ -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, mi">64);
memset(CORE.Input.Gamepad.name[jid], 0, k">sizeof(CORE.Input.Gamepad.name[jid]));
}
}

Loading…
Cancel
Save