From e2e3d193516d5ddc9013e862bbe7e3dc974428c3 Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Mon, 20 Aug 2007 22:06:54 -0600 Subject: [PATCH] dinput: Don't try to create non existing device (/dev/js*). --- dlls/dinput/joystick_linux.c | 71 ++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index f155f1882ee..ef5b9f39d27 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -583,48 +583,55 @@ static unsigned short get_joystick_index(REFGUID guid) static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev) { - unsigned short index; + unsigned short index; - if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS) { - if ((riid == NULL) || - IsEqualGUID(&IID_IDirectInputDeviceA,riid) || - IsEqualGUID(&IID_IDirectInputDevice2A,riid) || - IsEqualGUID(&IID_IDirectInputDevice7A,riid) || - IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { - return alloc_device(rguid, &JoystickAvt, dinput, pdev, index); - } else { - WARN("no interface\n"); - *pdev = 0; - return DIERR_NOINTERFACE; + find_joystick_devices(); + *pdev = NULL; + + if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS && + joystick_devices_count && index < joystick_devices_count) + { + if ((riid == NULL) || + IsEqualGUID(&IID_IDirectInputDeviceA, riid) || + IsEqualGUID(&IID_IDirectInputDevice2A, riid) || + IsEqualGUID(&IID_IDirectInputDevice7A, riid) || + IsEqualGUID(&IID_IDirectInputDevice8A, riid)) + { + return alloc_device(rguid, &JoystickAvt, dinput, pdev, index); + } + + WARN("no interface\n"); + return DIERR_NOINTERFACE; } - } - WARN("invalid device GUID\n"); - *pdev = 0; - return DIERR_DEVICENOTREG; + WARN("invalid device GUID\n"); + return DIERR_DEVICENOTREG; } static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev) { - unsigned short index; + unsigned short index; - if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS) { - if ((riid == NULL) || - IsEqualGUID(&IID_IDirectInputDeviceW,riid) || - IsEqualGUID(&IID_IDirectInputDevice2W,riid) || - IsEqualGUID(&IID_IDirectInputDevice7W,riid) || - IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { - return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index); - } else { - WARN("no interface\n"); - *pdev = 0; - return DIERR_NOINTERFACE; + find_joystick_devices(); + *pdev = NULL; + + if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS && + joystick_devices_count && index < joystick_devices_count) + { + if ((riid == NULL) || + IsEqualGUID(&IID_IDirectInputDeviceW, riid) || + IsEqualGUID(&IID_IDirectInputDevice2W, riid) || + IsEqualGUID(&IID_IDirectInputDevice7W, riid) || + IsEqualGUID(&IID_IDirectInputDevice8W, riid)) + { + return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index); + } + WARN("no interface\n"); + return DIERR_NOINTERFACE; } - } - WARN("invalid device GUID\n"); - *pdev = 0; - return DIERR_DEVICENOTREG; + WARN("invalid device GUID\n"); + return DIERR_DEVICENOTREG; } #undef MAX_JOYSTICKS