From b82d5fcfff88c16e3057bfd48cf2c312e1460944 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 11 Jul 2017 09:52:40 +0200 Subject: [PATCH] Reset the number of bytes to zero on error The hidapi read and write functions return a negative value if an error occurs. Those negative values should not be returned to the caller as the actual number of bytes (or used in the logging). The value is reset to zero instead. --- src/usbhid.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usbhid.c b/src/usbhid.c index b99cf21..99df918 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -362,6 +362,7 @@ dc_usbhid_read (dc_usbhid_t *usbhid, void *data, size_t size, size_t *actual) if (nbytes < 0) { ERROR (usbhid->context, "Usb read interrupt transfer failed."); status = DC_STATUS_IO; + nbytes = 0; goto out; } #endif @@ -422,6 +423,7 @@ dc_usbhid_write (dc_usbhid_t *usbhid, const void *data, size_t size, size_t *act if (nbytes < 0) { ERROR (usbhid->context, "Usb write interrupt transfer failed."); status = DC_STATUS_IO; + nbytes = 0; goto out; } #endif