examples: check value returned by libusb_bulk_transfer()
authorLudovic Rousseau <ludovic.rousseau+github@gmail.com>
Sun, 22 Sep 2013 19:25:00 +0000 (21:25 +0200)
committerLudovic Rousseau <ludovic.rousseau+github@gmail.com>
Sat, 28 Sep 2013 10:17:58 +0000 (12:17 +0200)
Problem detected by the Coverity tool
CID 1042540 (#1 of 1): Unchecked return value (CHECKED_RETURN)1.
check_return: Calling function "libusb_bulk_transfer(struct
libusb_device_handle *, unsigned char, unsigned char *, int, int *,
unsigned int)" without checking return value (as is done elsewhere 4 out
of 5 times).

examples/xusb.c
libusb/version_nano.h

index 4df65c4..829ce41 100644 (file)
@@ -415,6 +415,7 @@ static void get_sense(libusb_device_handle *handle, uint8_t endpoint_in, uint8_t
        uint8_t sense[18];
        uint32_t expected_tag;
        int size;
+       int rc;
 
        // Request Sense
        printf("Request Sense:\n");
@@ -424,7 +425,12 @@ static void get_sense(libusb_device_handle *handle, uint8_t endpoint_in, uint8_t
        cdb[4] = REQUEST_SENSE_LENGTH;
 
        send_mass_storage_command(handle, endpoint_out, 0, cdb, LIBUSB_ENDPOINT_IN, REQUEST_SENSE_LENGTH, &expected_tag);
-       libusb_bulk_transfer(handle, endpoint_in, (unsigned char*)&sense, REQUEST_SENSE_LENGTH, &size, 1000);
+       rc = libusb_bulk_transfer(handle, endpoint_in, (unsigned char*)&sense, REQUEST_SENSE_LENGTH, &size, 1000);
+       if (rc < 0)
+       {
+               printf("libusb_bulk_transfer failed: %s\n", libusb_error_name(rc));
+               return;
+       }
        printf("   received %d bytes\n", size);
 
        if ((sense[0] != 0x70) && (sense[0] != 0x71)) {
index 0d147a7..2000b91 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10841
+#define LIBUSB_NANO 10842