Vitaliy Margolen : dinput: Zero the out buffer.

Alexandre Julliard julliard at winehq.org
Mon Jul 28 08:07:25 CDT 2008


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

Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date:   Sun Jul 27 09:53:34 2008 -0600

dinput: Zero the out buffer.

---

 dlls/dinput/device.c              |    4 +++-
 dlls/dinput/device_private.h      |    2 +-
 dlls/dinput/joystick_linux.c      |    2 +-
 dlls/dinput/joystick_linuxinput.c |    2 +-
 dlls/dinput/keyboard.c            |    2 +-
 dlls/dinput/mouse.c               |    2 +-
 dlls/dinput/tests/keyboard.c      |   18 ++++++++++++------
 7 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 54fefbe..7d9f728 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -265,11 +265,13 @@ DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
 }
 
 /* Conversion between internal data buffer and external data buffer */
-void fill_DataFormat(void *out, const void *in, const DataFormat *df) {
+void fill_DataFormat(void *out, DWORD size, const void *in, const DataFormat *df)
+{
     int i;
     const char *in_c = in;
     char *out_c = (char *) out;
 
+    memset(out, 0, size);
     if (df->dt == NULL) {
 	/* This means that the app uses Wine's internal data format */
 	memcpy(out, in, df->internal_format_size);
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index 9321250..7b62a50 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -76,7 +76,7 @@ extern BOOL get_app_key(HKEY*, HKEY*);
 extern DWORD get_config_key(HKEY, HKEY, const char*, char*, DWORD);
 
 /* Routines to do DataFormat / WineFormat conversions */
-extern void fill_DataFormat(void *out, const void *in, const DataFormat *df) ;
+extern void fill_DataFormat(void *out, DWORD size, const void *in, const DataFormat *df) ;
 extern HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format);
 extern void release_DataFormat(DataFormat *df) ;
 extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq);
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 9dead0a..bcac66a 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -767,7 +767,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceState(
     joy_polldev(This);
 
     /* convert and copy data to user supplied buffer */
-    fill_DataFormat(ptr, &This->js, &This->base.data_format);
+    fill_DataFormat(ptr, len, &This->js, &This->base.data_format);
 
     return DI_OK;
 }
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index d3f7dc0..a7c9c63 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -802,7 +802,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceState(
     joy_polldev(This);
 
     /* convert and copy data to user supplied buffer */
-    fill_DataFormat(ptr, &This->js, &This->base.data_format);
+    fill_DataFormat(ptr, len, &This->js, &This->base.data_format);
 
     return DI_OK;
 }
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index cb290f6..b2c4942 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -283,7 +283,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(
 	}
     }
 
-    fill_DataFormat(ptr, This->DInputKeyState, &This->base.data_format);
+    fill_DataFormat(ptr, len, This->DInputKeyState, &This->base.data_format);
     LeaveCriticalSection(&This->base.crit);
 
     return DI_OK;
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 1dc6a03..a361057 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -490,7 +490,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
 
     EnterCriticalSection(&This->base.crit);
     /* Copy the current mouse state */
-    fill_DataFormat(ptr, &(This->m_state), &This->base.data_format);
+    fill_DataFormat(ptr, len, &This->m_state, &This->base.data_format);
 
     /* Initialize the buffer when in relative mode */
     if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS))
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
index d427e65..de55d32 100644
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -70,20 +70,21 @@ static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd)
     HRESULT hr;
     LPDIRECTINPUTDEVICE pKeyboard;
     BYTE kbd_state[256];
-    BYTE custom_state[4];
+    LONG custom_state[6];
+    int i;
     DIOBJECTDATAFORMAT dodf[] =
         {
-            { &GUID_Key, 0, DIDFT_MAKEINSTANCE(DIK_Q)|DIDFT_BUTTON, 0 },
-            { &GUID_Key, 1, DIDFT_MAKEINSTANCE(DIK_W)|DIDFT_BUTTON, 0 },
-            { &GUID_Key, 2, DIDFT_MAKEINSTANCE(DIK_E)|DIDFT_BUTTON, 0 },
-            { &GUID_Key, 3, DIDFT_MAKEINSTANCE(DIK_R)|DIDFT_BUTTON, 0 },
+            { &GUID_Key, sizeof(LONG) * 0, DIDFT_MAKEINSTANCE(DIK_Q)|DIDFT_BUTTON, 0 },
+            { &GUID_Key, sizeof(LONG) * 1, DIDFT_MAKEINSTANCE(DIK_W)|DIDFT_BUTTON, 0 },
+            { &GUID_Key, sizeof(LONG) * 2, DIDFT_MAKEINSTANCE(DIK_E)|DIDFT_BUTTON, 0 },
+            { &GUID_Key, sizeof(LONG) * 4, DIDFT_MAKEINSTANCE(DIK_R)|DIDFT_BUTTON, 0 },
         };
 
     DIDATAFORMAT df;
     df.dwSize = sizeof( df );
     df.dwObjSize = sizeof( DIOBJECTDATAFORMAT );
     df.dwFlags = DIDF_RELAXIS;
-    df.dwDataSize = sizeof( dodf )/sizeof( dodf[0] );
+    df.dwDataSize = sizeof( custom_state );
     df.dwNumObjs = sizeof( dodf )/sizeof( dodf[0] );
     df.rgodf = dodf;
 
@@ -120,6 +121,11 @@ static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd)
     hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
     ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(256,) should have failed: %08x\n", hr);
 
+    memset(custom_state, 0x56, sizeof(custom_state));
+    IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(custom_state), custom_state);
+    for (i = 0; i < sizeof(custom_state) / sizeof(custom_state[0]); i++)
+        ok(custom_state[i] == 0, "Should be zeroed, got 0x%08x\n", custom_state[i]);
+
     if (pKeyboard) IUnknown_Release(pKeyboard);
 }
 




More information about the wine-cvs mailing list