Even if scandir results in success, we may still fail and return an empty
device path. Move the error message down, the code in between the old
position of this hunk and the new position is not hit if scandir fails
anyway.

Signed-off-by: Peter Hutterer <[email protected]>
---
 src/device.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/device.cpp b/src/device.cpp
index 884ba3b..12b3e56 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -63,17 +63,12 @@ static int _event_device_filter(const struct dirent *d) {
 }
 
 void xorg::testing::evemu::Device::GuessDeviceNode(time_t ctime) {
-  struct dirent **event_devices;
+  struct dirent **event_devices = NULL;
   int n_event_devices;
 
   n_event_devices = scandir(SYS_INPUT_DIR, &event_devices,
                             _event_device_filter, _event_device_compare);
 
-  if (n_event_devices < 0) {
-    std::cerr << "Failed to guess device node." << std::endl;
-    return;
-  }
-
   bool found = false;
   for (int i = 0; i < n_event_devices && !found; i++) {
     std::stringstream s;
@@ -95,6 +90,9 @@ void xorg::testing::evemu::Device::GuessDeviceNode(time_t 
ctime) {
     close(fd);
   }
 
+  if (!found)
+    std::cerr << "Failed to guess device node." << std::endl;
+
   for (int i = 0; i < n_event_devices; i++)
     free(event_devices[i]);
   free(event_devices);
-- 
1.7.11.2

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to