From c498f4e8ab86aeda12ae11dfbd4f9b9f16d9f291 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 6 Oct 2018 07:49:59 +0530 Subject: [PATCH] Linux: Include the null byte in joystick path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This potential bug was found thanks to gcc 8’s -Wstringop-truncation warning. --- glfw/linux_joystick.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/glfw/linux_joystick.c b/glfw/linux_joystick.c index 2777d0b38..db5a0e7a0 100644 --- a/glfw/linux_joystick.c +++ b/glfw/linux_joystick.c @@ -228,7 +228,7 @@ static GLFWbool openJoystickDevice(const char* path) return GLFW_FALSE; } - strncpy(linjs.path, path, sizeof(linjs.path)); + strncpy(linjs.path, path, sizeof(linjs.path) - 1); memcpy(&js->linjs, &linjs, sizeof(linjs)); pollAbsState(js); @@ -431,4 +431,3 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) void _glfwPlatformUpdateGamepadGUID(char* guid) { } -