mirror of
https://github.com/RPCS3/hidapi.git
synced 2026-07-19 13:34:37 -04:00
windows: Limit hid_read() return value to buffer length
hid_read() and hid_read_timeout() now return the number of bytes copied, instead of the number of bytes returned by GetOverlappekdResult() (which is the maximum report size for the device). This limits the return value to the requested length (buffer size), matching the behavior on other platforms.
This commit is contained in:
committed by
Alan Ott
parent
99d0219a87
commit
171a521b91
+3
-3
@@ -662,6 +662,7 @@ end_of_function:
|
||||
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
|
||||
{
|
||||
DWORD bytes_read = 0;
|
||||
size_t copy_len = 0;
|
||||
BOOL res;
|
||||
|
||||
/* Copy the handle for convenience. */
|
||||
@@ -709,14 +710,13 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
|
||||
number (0x0) on the beginning of the report anyway. To make this
|
||||
work like the other platforms, and to make it work more like the
|
||||
HID spec, we'll skip over this byte. */
|
||||
size_t copy_len;
|
||||
bytes_read--;
|
||||
copy_len = length > bytes_read ? bytes_read : length;
|
||||
memcpy(data, dev->read_buf+1, copy_len);
|
||||
}
|
||||
else {
|
||||
/* Copy the whole buffer, report number and all. */
|
||||
size_t copy_len = length > bytes_read ? bytes_read : length;
|
||||
copy_len = length > bytes_read ? bytes_read : length;
|
||||
memcpy(data, dev->read_buf, copy_len);
|
||||
}
|
||||
}
|
||||
@@ -727,7 +727,7 @@ end_of_function:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return bytes_read;
|
||||
return copy_len;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length)
|
||||
|
||||
Reference in New Issue
Block a user