Vitaliy Margolen : dinput: Don't try to create non existing device.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Aug 20 16:09:17 CDT 2007


Module: wine
Branch: master
Commit: f47c63a1f9ef7f110dc6bff2408cc6ff61eb419b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f47c63a1f9ef7f110dc6bff2408cc6ff61eb419b

Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date:   Sun Aug 19 22:26:19 2007 -0600

dinput: Don't try to create non existing device.

---

 dlls/dinput/joystick_linuxinput.c |   69 ++++++++++++++++++++++---------------
 1 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index feeb118..f3fc11e 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -505,24 +505,31 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE
 
     find_joydevs();
 
-    if ((index = get_joystick_index(rguid)) < MAX_JOYDEV) {
-      if ((riid == NULL) ||
-      IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
-      IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
-      IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
-      IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
-        *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index);
-        TRACE("Creating a Joystick device (%p)\n", *pdev);
-        if (*pdev==0) {
-          ERR("out of memory\n");
-          return DIERR_OUTOFMEMORY;
+    if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
+        have_joydevs && index < have_joydevs)
+    {
+        if ((riid == NULL) ||
+            IsEqualGUID(&IID_IDirectInputDeviceA,  riid) ||
+            IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
+            IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
+            IsEqualGUID(&IID_IDirectInputDevice8A, riid))
+        {
+            *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index);
+            TRACE("Created a Joystick device (%p)\n", *pdev);
+
+            if (*pdev == NULL)
+            {
+                ERR("out of memory\n");
+                return DIERR_OUTOFMEMORY;
+            }
+            return DI_OK;
         }
-        return DI_OK;
-      } else {
+
+        WARN("no interface\n");
         return DIERR_NOINTERFACE;
-      }
     }
 
+    WARN("invalid device GUID\n");
     return DIERR_DEVICENOTREG;
 }
 
@@ -533,24 +540,30 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE
 
     find_joydevs();
 
-    if ((index = get_joystick_index(rguid)) < MAX_JOYDEV) {
-      if ((riid == NULL) ||
-      IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
-      IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
-      IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
-      IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
-        *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
-        TRACE("Creating a Joystick device (%p)\n", *pdev);
-        if (*pdev==0) {
-          ERR("out of memory\n");
-          return DIERR_OUTOFMEMORY;
+    if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
+        have_joydevs && index < have_joydevs)
+    {
+        if ((riid == NULL) ||
+            IsEqualGUID(&IID_IDirectInputDeviceW,  riid) ||
+            IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
+            IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
+            IsEqualGUID(&IID_IDirectInputDevice8W, riid))
+        {
+            *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
+            TRACE("Created a Joystick device (%p)\n", *pdev);
+
+            if (*pdev == NULL)
+            {
+                ERR("out of memory\n");
+                return DIERR_OUTOFMEMORY;
+            }
+            return DI_OK;
         }
-        return DI_OK;
-      } else {
+        WARN("no interface\n");
         return DIERR_NOINTERFACE;
-      }
     }
 
+    WARN("invalid device GUID\n");
     return DIERR_DEVICENOTREG;
 }
 




More information about the wine-cvs mailing list