src/joystick/windows/SDL_windowsjoystick.c
changeset 13873 5bb6be4f2425
parent 13872 75c33f89d791
child 13944 b8c8ce11efc7
     1.1 --- a/src/joystick/windows/SDL_windowsjoystick.c	Fri May 29 13:37:21 2020 -0700
     1.2 +++ b/src/joystick/windows/SDL_windowsjoystick.c	Fri May 29 14:48:05 2020 -0700
     1.3 @@ -400,8 +400,9 @@
     1.4  WINDOWS_JoystickGetDeviceName(int device_index)
     1.5  {
     1.6      JoyStick_DeviceData *device = SYS_Joystick;
     1.7 +    int index;
     1.8  
     1.9 -    for (; device_index > 0; device_index--)
    1.10 +    for (index = device_index; index > 0; index--)
    1.11          device = device->pNext;
    1.12  
    1.13      return device->joystickname;
    1.14 @@ -458,25 +459,26 @@
    1.15  static int
    1.16  WINDOWS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    1.17  {
    1.18 -    JoyStick_DeviceData *joystickdevice = SYS_Joystick;
    1.19 +    JoyStick_DeviceData *device = SYS_Joystick;
    1.20 +    int index;
    1.21  
    1.22 -    for (; device_index > 0; device_index--)
    1.23 -        joystickdevice = joystickdevice->pNext;
    1.24 +    for (index = device_index; index > 0; index--)
    1.25 +        device = device->pNext;
    1.26  
    1.27      /* allocate memory for system specific hardware data */
    1.28 -    joystick->instance_id = joystickdevice->nInstanceID;
    1.29 +    joystick->instance_id = device->nInstanceID;
    1.30      joystick->hwdata =
    1.31          (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
    1.32      if (joystick->hwdata == NULL) {
    1.33          return SDL_OutOfMemory();
    1.34      }
    1.35      SDL_zerop(joystick->hwdata);
    1.36 -    joystick->hwdata->guid = joystickdevice->guid;
    1.37 +    joystick->hwdata->guid = device->guid;
    1.38  
    1.39 -    if (joystickdevice->bXInputDevice) {
    1.40 -        return SDL_XINPUT_JoystickOpen(joystick, joystickdevice);
    1.41 +    if (device->bXInputDevice) {
    1.42 +        return SDL_XINPUT_JoystickOpen(joystick, device);
    1.43      } else {
    1.44 -        return SDL_DINPUT_JoystickOpen(joystick, joystickdevice);
    1.45 +        return SDL_DINPUT_JoystickOpen(joystick, device);
    1.46      }
    1.47  }
    1.48