Workaround for a Windows libusb issue
When libusb uses the Windows HID api internally, it does automatically prepend a zero report ID to the data for devices which support only a single report. But apparently it also returns a size of one byte extra! As a workaround, the number of bytes is limited to the actual size. See commit c9ed92d3f55c259931527a27d018eb5791a176dd for a similar issue in the hidapi library.
This commit is contained in:
parent
ddb7276bf0
commit
bcb64b3297
14
src/usbhid.c
14
src/usbhid.c
@ -45,6 +45,7 @@
|
||||
#include "usbhid.h"
|
||||
#include "common-private.h"
|
||||
#include "context-private.h"
|
||||
#include "platform.h"
|
||||
|
||||
struct dc_usbhid_t {
|
||||
/* Library context. */
|
||||
@ -432,15 +433,16 @@ dc_usbhid_write (dc_usbhid_t *usbhid, const void *data, size_t size, size_t *act
|
||||
nbytes = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (nbytes > size) {
|
||||
nbytes = size;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
out:
|
||||
#ifdef _WIN32
|
||||
if (nbytes > size) {
|
||||
WARNING (usbhid->context, "Number of bytes exceeds the buffer size (" DC_PRINTF_SIZE " > " DC_PRINTF_SIZE ")!", nbytes, size);
|
||||
nbytes = size;
|
||||
}
|
||||
#endif
|
||||
|
||||
HEXDUMP (usbhid->context, DC_LOGLEVEL_INFO, "Write", (unsigned char *) data, nbytes);
|
||||
|
||||
out_invalidargs:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user