diff options
author | Artur Mądrzak <12701995+arturmadrzak@users.noreply.github.com> | 2020-10-18 21:17:37 +0200 |
---|---|---|
committer | Artur Mądrzak <artur@madrzak.eu> | 2020-10-18 21:26:35 +0200 |
commit | 56711c7ff5c406c51238148638ff3fa1906ac1b6 (patch) | |
tree | 49dd50795341c8ebda9e3041ba0cad1e35b52389 /src | |
parent | 55d4b179dc69c11430373c7de0aebc9759901927 (diff) | |
download | libmtp-56711c7ff5c406c51238148638ff3fa1906ac1b6.tar.gz |
Bugfix return value in cancel request
Comparing signed integer (ret) with unsigned integer/size_t result of sizeof(buffer). `usb_control_msg` returns one of LIBUSB_ERROR (that have negative values) or number of bytes transferred (positive value). The if condition remains false for "-1 < sizeof(buffer)" and function returns `PTP_RC_OK` instead of `PTP_ERROR_IO`. To solve this issue, explicitly cast sizeof result to signed int to make comparison correct. In this case there is no issue to reduce range of sizeof, as by design control packets are small.
Signed-off-by: Artur Mądrzak <artur@madrzak.eu>
Diffstat (limited to 'src')
-rw-r--r-- | src/libusb-glue.c | 2 | ||||
-rw-r--r-- | src/libusb1-glue.c | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/libusb-glue.c b/src/libusb-glue.c index 5e84b1d..3c1b023 100644 --- a/src/libusb-glue.c +++ b/src/libusb-glue.c @@ -1645,7 +1645,7 @@ ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) { (char *) buffer, sizeof(buffer), ptp_usb->timeout); - if (ret < sizeof(buffer)) + if (ret < (int)sizeof(buffer)) return PTP_ERROR_IO; return PTP_RC_OK; } diff --git a/src/libusb1-glue.c b/src/libusb1-glue.c index 6ba3eb7..9cc4781 100644 --- a/src/libusb1-glue.c +++ b/src/libusb1-glue.c @@ -1852,7 +1852,7 @@ ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) { buffer, sizeof(buffer), ptp_usb->timeout); - if (ret < sizeof(buffer)) + if (ret < (int)sizeof(buffer)) return PTP_ERROR_IO; return PTP_RC_OK; } @@ -1874,7 +1874,7 @@ ptp_usb_control_device_status_request (PTPParams *params) { buffer, sizeof(buffer), ptp_usb->timeout); - if (ret < sizeof(buffer)) + if (ret < (int)sizeof(buffer)) return PTP_ERROR_IO; ret = dtoh16a(&buffer[2]); |