diff options
Diffstat (limited to 'libusb/os')
-rw-r--r-- | libusb/os/poll_windows.c | 7 | ||||
-rw-r--r-- | libusb/os/windows_common.h | 2 | ||||
-rw-r--r-- | libusb/os/windows_usb.c | 11 |
3 files changed, 13 insertions, 7 deletions
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index da97ca9..6bb91af 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -91,8 +91,11 @@ static BOOL (__stdcall *pCancelIoEx)(HANDLE, LPOVERLAPPED) = NULL; static inline void setup_cancel_io(void) { - pCancelIoEx = (BOOL (__stdcall *)(HANDLE,LPOVERLAPPED)) - GetProcAddress(GetModuleHandleA("KERNEL32"), "CancelIoEx"); + HMODULE hKernel32 = GetModuleHandleA("KERNEL32"); + if (hKernel32 != NULL) { + pCancelIoEx = (BOOL (__stdcall *)(HANDLE,LPOVERLAPPED)) + GetProcAddress(hKernel32, "CancelIoEx"); + } usbi_dbg("Will use CancelIo%s for I/O cancellation", Use_Duplicate_Handles?"":"Ex"); } diff --git a/libusb/os/windows_common.h b/libusb/os/windows_common.h index 3230b02..1da72bd 100644 --- a/libusb/os/windows_common.h +++ b/libusb/os/windows_common.h @@ -49,7 +49,7 @@ #define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2)) #define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count) #define safe_strlen(str) ((str==NULL)?0:strlen(str)) -#define safe_sprintf _snprintf +#define safe_sprintf(dst, count, ...) do {_snprintf(dst, count, __VA_ARGS__); (dst)[(count)-1] = 0; } while(0) #define safe_stprintf _sntprintf #define safe_tcslen(str) ((str==NULL)?0:_tcslen(str)) #define safe_unref_device(dev) do {if (dev != NULL) {libusb_unref_device(dev); dev = NULL;}} while(0) diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 1a0c846..d8156b8 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -151,7 +151,7 @@ static char *windows_error_str(uint32_t retval) static char err_string[ERR_BUFFER_SIZE]; DWORD size; - size_t i; + ssize_t i; uint32_t error_code, format_error; error_code = retval?retval:GetLastError(); @@ -170,7 +170,7 @@ static char err_string[ERR_BUFFER_SIZE]; safe_sprintf(err_string, ERR_BUFFER_SIZE, "Unknown error code %u", error_code); } else { // Remove CR/LF terminators - for (i=safe_strlen(err_string)-1; ((err_string[i]==0x0A) || (err_string[i]==0x0D)); i--) { + for (i=safe_strlen(err_string)-1; (i>=0) && ((err_string[i]==0x0A) || (err_string[i]==0x0D)); i--) { err_string[i] = 0; } } @@ -535,6 +535,9 @@ static unsigned long htab_hash(char* str) int c; char* sz = str; + if (str == NULL) + return 0; + // Compute main hash value (algorithm suggested by Nokia) while ((c = *sz++) != 0) r = ((r << 5) + r) + c; @@ -2673,7 +2676,7 @@ static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev DWORD err; int i; SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL; - HDEVINFO dev_info; + HDEVINFO dev_info = INVALID_HANDLE_VALUE; SP_DEVINFO_DATA dev_info_data; char* dev_path_no_guid = NULL; char filter_path[] = "\\\\.\\libusb0-0000"; @@ -4019,7 +4022,7 @@ static int hid_submit_bulk_transfer(int sub_api, struct usbi_transfer *itransfer if (direction_in) { transfer_priv->hid_dest = transfer->buffer; - usbi_dbg("reading %d bytes (report ID: 0x%02X)", length, transfer_priv->hid_buffer[0]); + usbi_dbg("reading %d bytes (report ID: 0x00)", length); ret = ReadFile(wfd.handle, transfer_priv->hid_buffer, length+1, &size, wfd.overlapped); } else { if (!priv->hid->uses_report_ids[1]) { |