Change the processed value not the bufsiz in response to an end of message marker.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/usbutils.c b/usbutils.c
index fe6f8f4..629e36e 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2609,17 +2609,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
break;
}
- /* If we found the end of message marker, just use that data and
- * return success. */
- if (eom) {
- size_t eomlen = (void *)eom - (void *)usbbuf + endlen;
-
- if (eomlen < bufsiz) {
- bufsiz = eomlen;
- err = LIBUSB_SUCCESS;
- }
- }
-
// N.B. usbdev->buffer was emptied before the while() loop
if (tot > (int)bufsiz) {
usbdev->bufamt = tot - bufsiz;
@@ -2630,7 +2619,13 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
cgpu->drv->name, cgpu->device_id, usbdev->bufamt);
}
- *processed = tot;
+ /* If we found the end of message marker, just use that data and
+ * return success. */
+ if (eom) {
+ *processed = (void *)eom - (void *)usbbuf + endlen;
+ err = LIBUSB_SUCCESS;
+ } else
+ *processed = tot;
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
if (err && err != LIBUSB_ERROR_TIMEOUT) {