From bcb64b3297b0366331de7aed12f1fdf7165ac0d6 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 22 Sep 2017 22:16:56 +0200 Subject: [PATCH] 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. --- src/usbhid.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/usbhid.c b/src/usbhid.c index b697f47..38931b8 100644 --- a/src/usbhid.c +++ b/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: