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:
Mark A. Tsuchida
2013-12-21 13:01:28 -08:00
committed by Alan Ott
parent 99d0219a87
commit 171a521b91
+3 -3
View File
@@ -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)