@@ -461,7 +461,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
461461 double device_size ;
462462 uint8_t cdb [16 ]; // SCSI Command Descriptor Block
463463 uint8_t buffer [64 ];
464- char vid [9 ], pid [9 ], rev [5 ];
464+ unsigned char vid [9 ], pid [9 ], rev [5 ];
465465 unsigned char * data ;
466466 FILE * fd ;
467467
@@ -560,7 +560,7 @@ static int get_hid_record_size(uint8_t *hid_report_descriptor, int size, int typ
560560 uint8_t i , j = 0 ;
561561 uint8_t offset ;
562562 int record_size [3 ] = {0 , 0 , 0 };
563- int nb_bits = 0 , nb_items = 0 ;
563+ unsigned int nb_bits = 0 , nb_items = 0 ;
564564 bool found_record_marker ;
565565
566566 found_record_marker = false;
@@ -575,7 +575,7 @@ static int get_hid_record_size(uint8_t *hid_report_descriptor, int size, int typ
575575 case 0x94 : // count
576576 nb_items = 0 ;
577577 for (j = 1 ; j < offset ; j ++ ) {
578- nb_items = ((uint32_t )hid_report_descriptor [i + j ]) << (8 * (j - 1 ));
578+ nb_items = ((unsigned int )hid_report_descriptor [i + j ]) << (8U * (j - 1U ));
579579 }
580580 break ;
581581 case 0x80 : // input
@@ -623,9 +623,9 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
623623 printf (" Failed\n" );
624624 return -1 ;
625625 }
626- display_buffer_hex (hid_report_descriptor , descriptor_size );
626+ display_buffer_hex (hid_report_descriptor , ( unsigned int ) descriptor_size );
627627 if ((binary_dump ) && ((fd = fopen (binary_name , "w" )) != NULL )) {
628- if (fwrite (hid_report_descriptor , 1 , descriptor_size , fd ) != (size_t )descriptor_size ) {
628+ if (fwrite (hid_report_descriptor , 1 , ( size_t ) descriptor_size , fd ) != (size_t )descriptor_size ) {
629629 printf (" Error writing descriptor to file\n" );
630630 }
631631 fclose (fd );
@@ -634,8 +634,10 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
634634 size = get_hid_record_size (hid_report_descriptor , descriptor_size , HID_REPORT_TYPE_FEATURE );
635635 if (size <= 0 ) {
636636 printf ("\nSkipping Feature Report readout (None detected)\n" );
637+ } else if (size > UINT16_MAX ) {
638+ printf ("\nSkipping Feature Report readout (bigger than UINT16_MAX)\n" );
637639 } else {
638- report_buffer = (uint8_t * ) calloc (size , 1 );
640+ report_buffer = (uint8_t * ) calloc (1 , ( size_t ) size );
639641 if (report_buffer == NULL ) {
640642 return -1 ;
641643 }
@@ -644,7 +646,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
644646 r = libusb_control_transfer (handle , LIBUSB_ENDPOINT_IN |LIBUSB_REQUEST_TYPE_CLASS |LIBUSB_RECIPIENT_INTERFACE ,
645647 HID_GET_REPORT , (HID_REPORT_TYPE_FEATURE <<8 )|0 , 0 , report_buffer , (uint16_t )size , 5000 );
646648 if (r >= 0 ) {
647- display_buffer_hex (report_buffer , size );
649+ display_buffer_hex (report_buffer , ( unsigned int ) size );
648650 } else {
649651 switch (r ) {
650652 case LIBUSB_ERROR_NOT_FOUND :
@@ -665,8 +667,10 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
665667 size = get_hid_record_size (hid_report_descriptor , descriptor_size , HID_REPORT_TYPE_INPUT );
666668 if (size <= 0 ) {
667669 printf ("\nSkipping Input Report readout (None detected)\n" );
670+ } else if (size > UINT16_MAX ) {
671+ printf ("\nSkipping Input Report readout (bigger than UINT16_MAX)\n" );
668672 } else {
669- report_buffer = (uint8_t * ) calloc (size , 1 );
673+ report_buffer = (uint8_t * ) calloc (1 , ( size_t ) size );
670674 if (report_buffer == NULL ) {
671675 return -1 ;
672676 }
@@ -675,7 +679,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
675679 r = libusb_control_transfer (handle , LIBUSB_ENDPOINT_IN |LIBUSB_REQUEST_TYPE_CLASS |LIBUSB_RECIPIENT_INTERFACE ,
676680 HID_GET_REPORT , (HID_REPORT_TYPE_INPUT <<8 )|0x00 , 0 , report_buffer , (uint16_t )size , 5000 );
677681 if (r >= 0 ) {
678- display_buffer_hex (report_buffer , size );
682+ display_buffer_hex (report_buffer , ( unsigned int ) size );
679683 } else {
680684 switch (r ) {
681685 case LIBUSB_ERROR_TIMEOUT :
@@ -695,7 +699,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
695699 printf ("\nTesting interrupt read using endpoint %02X...\n" , endpoint_in );
696700 r = libusb_interrupt_transfer (handle , endpoint_in , report_buffer , size , & size , 5000 );
697701 if (r >= 0 ) {
698- display_buffer_hex (report_buffer , size );
702+ display_buffer_hex (report_buffer , ( unsigned int ) size );
699703 } else {
700704 printf (" %s\n" , libusb_strerror ((enum libusb_error )r ));
701705 }
@@ -753,7 +757,7 @@ static void read_ms_winsub_feature_descriptors(libusb_device_handle *handle, uin
753757 perr (" Failed: %s" , libusb_strerror ((enum libusb_error )r ));
754758 return ;
755759 } else {
756- display_buffer_hex (os_desc , r );
760+ display_buffer_hex (os_desc , ( unsigned int ) r );
757761 }
758762 }
759763}
@@ -824,7 +828,7 @@ static int test_device(uint16_t vid, uint16_t pid)
824828 struct libusb_device_descriptor dev_desc ;
825829 const char * const speed_name [6 ] = { "Unknown" , "1.5 Mbit/s (USB LowSpeed)" , "12 Mbit/s (USB FullSpeed)" ,
826830 "480 Mbit/s (USB HighSpeed)" , "5000 Mbit/s (USB SuperSpeed)" , "10000 Mbit/s (USB SuperSpeedPlus)" };
827- char string [128 ];
831+ unsigned char string [128 ];
828832 uint8_t string_index [3 ]; // indexes of the string descriptors
829833 uint8_t endpoint_in = 0 , endpoint_out = 0 ; // default IN and OUT endpoints
830834
@@ -960,13 +964,13 @@ static int test_device(uint16_t vid, uint16_t pid)
960964 if (string_index [i ] == 0 ) {
961965 continue ;
962966 }
963- if (libusb_get_string_descriptor_ascii (handle , string_index [i ], ( unsigned char * ) string , sizeof (string )) > 0 ) {
967+ if (libusb_get_string_descriptor_ascii (handle , string_index [i ], string , sizeof (string )) > 0 ) {
964968 printf (" String (0x%02X): \"%s\"\n" , string_index [i ], string );
965969 }
966970 }
967971
968972 printf ("\nReading OS string descriptor:" );
969- r = libusb_get_string_descriptor (handle , MS_OS_DESC_STRING_INDEX , 0 , ( unsigned char * ) string , MS_OS_DESC_STRING_LENGTH );
973+ r = libusb_get_string_descriptor (handle , MS_OS_DESC_STRING_INDEX , 0 , string , MS_OS_DESC_STRING_LENGTH );
970974 if (r == MS_OS_DESC_STRING_LENGTH && memcmp (ms_os_desc_string , string , sizeof (ms_os_desc_string )) == 0 ) {
971975 // If this is a Microsoft OS String Descriptor,
972976 // attempt to read the WinUSB extended Feature Descriptors
@@ -991,7 +995,7 @@ static int test_device(uint16_t vid, uint16_t pid)
991995 printf (" bFunctionSubClass: %02X\n" , iad -> bFunctionSubClass );
992996 printf (" bFunctionProtocol: %02X\n" , iad -> bFunctionProtocol );
993997 if (iad -> iFunction ) {
994- if (libusb_get_string_descriptor_ascii (handle , iad -> iFunction , ( unsigned char * ) string , sizeof (string )) > 0 )
998+ if (libusb_get_string_descriptor_ascii (handle , iad -> iFunction , string , sizeof (string )) > 0 )
995999 printf (" iFunction: %u (%s)\n" , iad -> iFunction , string );
9961000 else
9971001 printf (" iFunction: %u (libusb_get_string_descriptor_ascii failed!)\n" , iad -> iFunction );
@@ -1017,6 +1021,7 @@ static int test_device(uint16_t vid, uint16_t pid)
10171021 break ;
10181022 case USE_SCSI :
10191023 CALL_CHECK_CLOSE (test_mass_storage (handle , endpoint_in , endpoint_out ), handle );
1024+ break ;
10201025 case USE_GENERIC :
10211026 break ;
10221027 }
0 commit comments