@@ -1673,10 +1673,11 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
16731673 }
16741674
16751675 if (dev -> shutdown_thread ) {
1676- /* This means the device has been disconnected.
1676+ /* The read thread is no longer running (device disconnected,
1677+ event loop failure, etc.).
16771678 An error code of -1 should be returned. */
16781679 bytes_read = -1 ;
1679- register_read_error (dev , "hid_read(_timeout): device is closing " );
1680+ register_read_error (dev , "hid_read(_timeout): read thread terminated " );
16801681 goto ret ;
16811682 }
16821683
@@ -1688,6 +1689,10 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
16881689 if (dev -> input_reports ) {
16891690 bytes_read = return_data (dev , data , length );
16901691 }
1692+ else {
1693+ /* Woken up by shutdown_thread without data. */
1694+ register_read_error (dev , "hid_read(_timeout): read thread terminated" );
1695+ }
16911696 }
16921697 else if (milliseconds > 0 ) {
16931698 /* Non-blocking, but called with timeout. */
@@ -1703,10 +1708,12 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
17031708 bytes_read = return_data (dev , data , length );
17041709 break ;
17051710 }
1711+ if (dev -> shutdown_thread ) {
1712+ register_read_error (dev , "hid_read(_timeout): read thread terminated" );
1713+ break ;
1714+ }
17061715
1707- /* If we're here, there was a spurious wake up
1708- or the read thread was shutdown. Run the
1709- loop again (ie: don't break). */
1716+ /* Spurious wake up. Loop again. */
17101717 }
17111718 else if (res == HIDAPI_THREAD_TIMED_OUT ) {
17121719 /* Timed out. */
@@ -1876,7 +1883,7 @@ int HID_API_EXPORT hid_send_output_report(hid_device *dev, const unsigned char *
18761883 if (skipped_report_id )
18771884 length ++ ;
18781885
1879- return length ;
1886+ return ( int ) length ;
18801887}
18811888
18821889int HID_API_EXPORT HID_API_CALL hid_get_input_report (hid_device * dev , unsigned char * data , size_t length )
@@ -2055,7 +2062,7 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
20552062{
20562063 const char * name , * description , * context ;
20572064 char * buffer ;
2058- size_t len ;
2065+ int len ;
20592066 hidapi_error_ctx * err ;
20602067
20612068 if (!dev ) {
@@ -2093,12 +2100,12 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
20932100 return L"Error string format error" ;
20942101 }
20952102
2096- buffer = malloc (len + 1 ); /* +1 for terminating NULL */
2103+ buffer = malloc (( size_t ) len + 1 ); /* +1 for terminating NULL */
20972104 if (!buffer ) {
20982105 return L"Error string memory allocation error" ;
20992106 }
21002107
2101- len = snprintf (buffer , len + 1 , "%s: (%s) %s" , context , name , description );
2108+ len = snprintf (buffer , ( size_t ) len + 1 , "%s: (%s) %s" , context , name , description );
21022109
21032110 if (len <= 0 ) {
21042111 free (buffer );
0 commit comments