Module: wine Branch: master Commit: b75bd86ebd21c00c59ab689d170bd61dc1a30cf4 URL: https://gitlab.winehq.org/wine/wine/-/commit/b75bd86ebd21c00c59ab689d170bd61...
Author: Rémi Bernon rbernon@codeweavers.com Date: Tue Mar 21 14:26:32 2023 +0100
dinput: Count the actual number of object formats in SetActionMap.
Fixes crash introduced by 7b3f3d60782c63edd621353a635616f4cea029da, as SetActionMap is now called with unsupposed flags from the tests and skips some objects.
---
dlls/dinput/device.c | 3 ++- dlls/dinput/tests/joystick8.c | 18 ++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 407e4f52a38..3b3912ce9d2 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2028,7 +2028,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D /* Construct the dataformat and actionmap */ obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; - data_format.dwNumObjs = num_actions; + data_format.dwNumObjs = 0;
action_map = malloc( sizeof(ActionMap) * num_actions );
@@ -2051,6 +2051,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D action_map[action].offset = offset; obj_df[action].dwOfs = offset; offset += (type & DIDFT_BUTTON) ? 1 : 4; + data_format.dwNumObjs++;
action++; } diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 5295ee6c169..86747652d60 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -1031,9 +1031,7 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e
hr = IDirectInputDevice8_Acquire( device ); - todo_wine ok( hr == DI_OK, "Acquire returned: %#lx\n", hr ); - if (hr != DI_OK) goto skip_input;
hr = IDirectInputDevice8_SetActionMap( device, &action_format, L"username", DIDSAM_DEFAULT ); ok( hr == DIERR_ACQUIRED, "SetActionMap returned %#lx\n", hr ); @@ -1045,7 +1043,6 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e send_hid_input( file, &injected_input[0], sizeof(*injected_input) ); res = WaitForSingleObject( event, 100 ); } - todo_wine ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" );
for (i = 0; i < ARRAY_SIZE(injected_input); ++i) @@ -1053,11 +1050,10 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e winetest_push_context( "state[%ld]", i );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), state ); - todo_wine ok( hr == DI_OK, "GetDeviceState returned: %#lx\n", hr ); - todo_wine_if( expect_state[i][0] ) + todo_wine ok( state[0] == expect_state[i][0], "got state[0] %+ld\n", state[0] ); - todo_wine_if( expect_state[i][1] ) + todo_wine_if( i != 2 ) ok( state[1] == expect_state[i][1], "got state[1] %+ld\n", state[1] ); todo_wine_if( expect_state[i][2] ) ok( state[2] == expect_state[i][2], "got state[2] %+ld\n", state[2] ); @@ -1078,7 +1074,7 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e
res = WaitForSingleObject( event, 100 ); if (i == 0 || i == 3) ok( res == WAIT_TIMEOUT, "WaitForSingleObject succeeded\n" ); - else todo_wine ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" ); + else ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" ); ResetEvent( event ); winetest_pop_context(); } @@ -1091,23 +1087,21 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e while (res--) { winetest_push_context( "%lu", res ); - todo_wine_if( expect_objdata[res].dwOfs ) + todo_wine check_member( objdata[res], expect_objdata[res], "%#lx", dwOfs ); - todo_wine_if( expect_objdata[res].dwData ) + todo_wine_if( res == 0 || res == 3 || res == 6 ) ok( objdata[res].dwData == expect_objdata[res].dwData || broken(objdata[res].dwData == -45 && expect_objdata[res].dwData == -43) /* 32-bit rounding */, "got dwData %+ld\n", objdata[res].dwData ); - todo_wine + todo_wine_if( res != 1 && res != 4 ) check_member( objdata[res], expect_objdata[res], "%#Ix", uAppData ); winetest_pop_context(); }
-skip_input: hr = IDirectInputDevice8_BuildActionMap( device, &action_format, L"username", DIDBAM_DEFAULT ); ok( hr == DI_OK, "BuildActionMap returned %#lx\n", hr );
hr = IDirectInputDevice8_Unacquire( device ); - todo_wine ok( hr == DI_OK, "Acquire returned: %#lx\n", hr );