From c6767d0af1c1d75a8ca1efe05359e50f586d8e9a Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Thu, 15 Aug 2013 23:15:11 +0200 Subject: [PATCH] Fixed crash in the Linux implementation of Joystick, when inotify failed to initialize --- src/SFML/Window/Linux/JoystickImpl.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/SFML/Window/Linux/JoystickImpl.cpp b/src/SFML/Window/Linux/JoystickImpl.cpp index 4db4b913..ccec0a31 100644 --- a/src/SFML/Window/Linux/JoystickImpl.cpp +++ b/src/SFML/Window/Linux/JoystickImpl.cpp @@ -53,12 +53,19 @@ namespace bool canRead(int descriptor) { - fd_set set; - FD_ZERO(&set); - FD_SET(descriptor, &set); - timeval timeout = {0, 0}; - return select(descriptor + 1, &set, NULL, NULL, &timeout) > 0 && - FD_ISSET(notifyFd, &set); + if (descriptor >= 0) + { + fd_set set; + FD_ZERO(&set); + FD_SET(descriptor, &set); + timeval timeout = {0, 0}; + return select(descriptor + 1, &set, NULL, NULL, &timeout) > 0 && + FD_ISSET(notifyFd, &set); + } + else + { + return false; + } } } @@ -102,7 +109,7 @@ void JoystickImpl::cleanup() inotify_rm_watch(notifyFd, inputFd); // Close the inotify file descriptor - if (inputFd >= 0) + if (notifyFd >= 0) ::close(notifyFd); } @@ -120,7 +127,7 @@ bool JoystickImpl::isConnected(unsigned int index) while (canRead(notifyFd)) { char buffer[128]; - read(notifyFd, buffer, sizeof(buffer)); + (void)read(notifyFd, buffer, sizeof(buffer)); } }