Vitaliy Margolen : dinput: Convert axis mapping array to int instead of BYTE. BYTE is unsigned and char isn't enough to store all possible axis values.

Alexandre Julliard julliard at winehq.org
Tue Sep 8 08:54:40 CDT 2009


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

Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date:   Mon Sep  7 11:59:16 2009 -0600

dinput: Convert axis mapping array to int instead of BYTE. BYTE is unsigned and char isn't enough to store all possible axis values.

---

 dlls/dinput/joystick.c            |    2 +-
 dlls/dinput/joystick_linux.c      |   43 ++++++++++++++++++-------------------
 dlls/dinput/joystick_linuxinput.c |    2 +-
 dlls/dinput/joystick_private.h    |    2 +-
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index e0be179..489342e 100644
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -448,7 +448,7 @@ DWORD joystick_map_pov(POINTL *p)
  * Setup the dinput options.
  */
 
-HRESULT setup_dinput_options(JoystickGenericImpl *This, const BYTE *default_axis_map)
+HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_map)
 {
     char buffer[MAX_PATH+16];
     HKEY hkey, appkey;
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 39731f3..bf31eaf 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -82,8 +82,7 @@ struct JoyDev
 
     BYTE axis_count;
     BYTE button_count;
-    BYTE dev_axes_map[ABS_MAX + 1];
-    int  have_axes_map;
+    int  *dev_axes_map;
 };
 
 typedef struct JoystickImpl JoystickImpl;
@@ -124,6 +123,7 @@ static INT find_joystick_devices(void)
     {
         int fd;
         struct JoyDev joydev, *new_joydevs;
+        BYTE axes_map[ABS_MAX + 1];
 
         snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i);
         if ((fd = open(joydev.device, O_RDONLY)) < 0)
@@ -152,28 +152,28 @@ static INT find_joystick_devices(void)
         }
 #endif
 
-        if (ioctl(fd, JSIOCGAXMAP, joydev.dev_axes_map) < 0)
+        if (ioctl(fd, JSIOCGAXMAP, axes_map) < 0)
         {
             WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
-            joydev.have_axes_map = 0;
+            joydev.dev_axes_map = NULL;
         }
         else
-        {
-            INT j;
-            joydev.have_axes_map = 1;
-
-            /* Remap to DI numbers */
-            for (j = 0; j < ABS_MAX; j++)
-                if (joydev.dev_axes_map[j] < 8)
-                    /* Axis match 1-to-1 */
-                    joydev.dev_axes_map[j] = j;
-                else if (joydev.dev_axes_map[j] == 16 ||
-                         joydev.dev_axes_map[j] == 17)
-                    /* POV axis */
-                    joydev.dev_axes_map[j] = 8;
-                else
-                    joydev.dev_axes_map[j] = -1;
-        }
+            if ((joydev.dev_axes_map = HeapAlloc(GetProcessHeap(), 0, joydev.axis_count * sizeof(int))))
+            {
+                INT j;
+
+                /* Remap to DI numbers */
+                for (j = 0; j < joydev.axis_count; j++)
+                    if (axes_map[j] < 8)
+                        /* Axis match 1-to-1 */
+                        joydev.dev_axes_map[j] = j;
+                    else if (axes_map[j] == 16 ||
+                             axes_map[j] == 17)
+                        /* POV axis */
+                        joydev.dev_axes_map[j] = 8;
+                    else
+                        joydev.dev_axes_map[j] = -1;
+            }
 
         close(fd);
 
@@ -324,8 +324,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
     newDevice->generic.deadzone = 0;
 
     /* do any user specified configuration */
-    hr = setup_dinput_options(&newDevice->generic, newDevice->joydev->have_axes_map ?
-                              newDevice->joydev->dev_axes_map : NULL);
+    hr = setup_dinput_options(&newDevice->generic, newDevice->joydev->dev_axes_map);
     if (hr != DI_OK)
         goto FAILED1;
 
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 4409b73..42daaeb 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -378,7 +378,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
     JoystickImpl* newDevice;
     LPDIDATAFORMAT df = NULL;
     int i, idx = 0;
-    BYTE default_axis_map[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS*2];
+    int default_axis_map[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS*2];
 
     newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
     if (!newDevice) return NULL;
diff --git a/dlls/dinput/joystick_private.h b/dlls/dinput/joystick_private.h
index 027e81a..aaa8294 100644
--- a/dlls/dinput/joystick_private.h
+++ b/dlls/dinput/joystick_private.h
@@ -53,7 +53,7 @@ typedef struct JoystickGenericImpl
 } JoystickGenericImpl;
 
 LONG joystick_map_axis(ObjProps *props, int val);
-HRESULT setup_dinput_options(JoystickGenericImpl *This, const BYTE *default_axis_map);
+HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_map);
 
 DWORD joystick_map_pov(POINTL *p);
 




More information about the wine-cvs mailing list