From 899117e7857796fd1b554e277b2f1a930c94484f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 4 Nov 2014 21:23:13 +0100 Subject: [PATCH] Possible control flow clarification. --- src/linux_joystick.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/linux_joystick.c b/src/linux_joystick.c index c0c4b3d7..136a8c37 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -93,7 +93,6 @@ static void pollJoystickEvents(void) { #ifdef __linux__ int i; - ssize_t result; struct js_event e; for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) @@ -105,19 +104,21 @@ static void pollJoystickEvents(void) for (;;) { errno = 0; - result = read(_glfw.linux_js[i].fd, &e, sizeof(e)); - - if (errno == ENODEV) + if (read(_glfw.linux_js[i].fd, &e, sizeof(e)) < 0) { - free(_glfw.linux_js[i].axes); - free(_glfw.linux_js[i].buttons); - free(_glfw.linux_js[i].name); + if (errno == ENODEV) + { + // The joystick was disconnected - memset(&_glfw.linux_js[i], 0, sizeof(_glfw.linux_js[i])); - } + free(_glfw.linux_js[i].axes); + free(_glfw.linux_js[i].buttons); + free(_glfw.linux_js[i].name); + + memset(&_glfw.linux_js[i], 0, sizeof(_glfw.linux_js[i])); + } - if (result == -1) break; + } // We don't care if it's an init event or not e.type &= ~JS_EVENT_INIT;