From 894e65649cda90fd0404b816a16585e2efffb1cd Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Tue, 12 Mar 2013 01:26:08 +0000 Subject: Windows: Fix multiple warnings * Most of these warnings are false positive from VS2012's "Run Code Analysis" * Also closes #98: "windows_usb.c:376:30: 'dev_info' may be used uninitialized" --- libusb/os/poll_windows.c | 7 +++++-- libusb/os/windows_common.h | 2 +- libusb/os/windows_usb.c | 11 +++++++---- libusb/version_nano.h | 2 +- msvc/config.h | 2 ++ 5 files changed, 16 insertions(+), 8 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)?"":str1), ((str2==NULL)?"":str2)) #define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"":str1), ((str2==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]) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 75f04ce..76481d3 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10625 +#define LIBUSB_NANO 10626 diff --git a/msvc/config.h b/msvc/config.h index 1814db5..bb542c5 100644 --- a/msvc/config.h +++ b/msvc/config.h @@ -7,6 +7,8 @@ /* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */ #pragma warning(disable:4200) +/* Disable: warning C6258: Using TerminateThread does not allow proper thread clean up */ +#pragma warning(disable: 6258) #if defined(_PREFAST_) /* Disable "Banned API" errors when using the MS's WDK OACR/Prefast */ #pragma warning(disable:28719) -- cgit v1.2.1