Windows: Fix reported length of synchronous control transfers
WinUSB control transfers that complete synchronously are incorrectly
having the actual transfer length set to the size of the transfer
buffer. If the control transfer is a read, the device may return less
data than the transfer buffer size. Fix this by reporting the actual
bytes transferred.
Closes #667
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index 136abb2..7cb17be 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -2472,7 +2472,7 @@
struct winusb_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
PWINUSB_SETUP_PACKET setup = (PWINUSB_SETUP_PACKET)transfer->buffer;
- ULONG size;
+ ULONG size, transferred;
HANDLE winusb_handle;
OVERLAPPED *overlapped;
int current_interface;
@@ -2510,13 +2510,13 @@
}
windows_force_sync_completion(overlapped, 0);
} else {
- if (!WinUSBX[sub_api].ControlTransfer(winusb_handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, NULL, overlapped)) {
+ if (!WinUSBX[sub_api].ControlTransfer(winusb_handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, &transferred, overlapped)) {
if (GetLastError() != ERROR_IO_PENDING) {
usbi_warn(ctx, "ControlTransfer failed: %s", windows_error_str(0));
return LIBUSB_ERROR_IO;
}
} else {
- windows_force_sync_completion(overlapped, size);
+ windows_force_sync_completion(overlapped, transferred);
}
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 9cef97f..18c8cb7 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11451
+#define LIBUSB_NANO 11452