Commit cda4abac authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

user32: Refactor and simplify GetRawInputDeviceInfoW cases.

parent 82211cd4
...@@ -686,8 +686,7 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT ...@@ -686,8 +686,7 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
{ {
RID_DEVICE_INFO info; RID_DEVICE_INFO info;
struct device *device; struct device *device;
const void *to_copy; DWORD len, data_len;
UINT to_copy_bytes, avail_bytes;
TRACE("handle %p, command %#x, data %p, data_size %p.\n", TRACE("handle %p, command %#x, data %p, data_size %p.\n",
handle, command, data, data_size); handle, command, data, data_size);
...@@ -703,45 +702,26 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT ...@@ -703,45 +702,26 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
return ~0U; return ~0U;
} }
/* each case below must set: data_len = *data_size;
* *data_size: length (meaning defined by command) of data we want to copy
* avail_bytes: number of bytes available in user buffer
* to_copy_bytes: number of bytes we want to copy into user buffer
* to_copy: pointer to data we want to copy into user buffer
*/
switch (command) switch (command)
{ {
case RIDI_DEVICENAME: case RIDI_DEVICENAME:
/* for RIDI_DEVICENAME, data_size is in characters, not bytes */ if ((len = wcslen(device->detail->DevicePath) + 1) <= data_len && data)
avail_bytes = *data_size * sizeof(WCHAR); memcpy(data, device->detail->DevicePath, len * sizeof(WCHAR));
*data_size = wcslen(device->detail->DevicePath) + 1; *data_size = len;
to_copy = device->detail->DevicePath;
to_copy_bytes = *data_size * sizeof(WCHAR);
break; break;
case RIDI_DEVICEINFO: case RIDI_DEVICEINFO:
avail_bytes = *data_size; if ((len = sizeof(info)) <= data_len && data)
info.cbSize = sizeof(info); memcpy(data, &device->info, len);
info = device->info; *data_size = len;
to_copy_bytes = sizeof(info);
*data_size = to_copy_bytes;
to_copy = &info;
break; break;
case RIDI_PREPARSEDDATA: case RIDI_PREPARSEDDATA:
avail_bytes = *data_size; len = device->data ? ((WINE_HIDP_PREPARSED_DATA*)device->data)->dwSize : 0;
if (device->info.dwType != RIM_TYPEHID) if (device->data && len <= data_len && data)
{ memcpy(data, device->data, len);
to_copy_bytes = 0; *data_size = len;
*data_size = 0;
to_copy = NULL;
}
else
{
to_copy_bytes = ((WINE_HIDP_PREPARSED_DATA*)device->data)->dwSize;
*data_size = to_copy_bytes;
to_copy = device->data;
}
break; break;
default: default:
...@@ -753,14 +733,12 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT ...@@ -753,14 +733,12 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
if (!data) if (!data)
return 0; return 0;
if (avail_bytes < to_copy_bytes) if (data_len < len)
{ {
SetLastError(ERROR_INSUFFICIENT_BUFFER); SetLastError(ERROR_INSUFFICIENT_BUFFER);
return ~0U; return ~0U;
} }
memcpy(data, to_copy, to_copy_bytes);
return *data_size; return *data_size;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment