diff options
author | Pete Batard <pbatard@gmail.com> | 2010-02-01 19:25:17 +0000 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-02-01 19:25:17 +0000 |
commit | 8a35c05b5a7666248acf21d79318bd151a3831d5 (patch) | |
tree | 8055a9539a35514b7e0a6bee9fcd1d993bdba762 | |
parent | 3e258645f41db07ef0b2f5998206e6a7f46f503e (diff) | |
download | libusb-8a35c05b5a7666248acf21d79318bd151a3831d5.tar.gz |
r130: fixed *size in HidD_GetPhysicalDescriptor and fixed various /W4 warnings for MSVC (windows files)
-rw-r--r-- | libusb/os/windows_compat.h | 5 | ||||
-rw-r--r-- | libusb/os/windows_usb.c | 8 | ||||
-rw-r--r-- | libusb/os/windows_usb.h | 44 |
3 files changed, 35 insertions, 22 deletions
diff --git a/libusb/os/windows_compat.h b/libusb/os/windows_compat.h index 5192a3e..e3fe695 100644 --- a/libusb/os/windows_compat.h +++ b/libusb/os/windows_compat.h @@ -21,6 +21,11 @@ */ #pragma once +#if defined(_MSC_VER) +// disable /W4 MSVC warnings that are benign +#pragma warning(disable:4127) // conditional expression is constant +#endif + #if !defined(ssize_t) #if defined (_WIN64) #define ssize_t __int64 diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 7719d01..860097d 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -754,6 +754,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs if ((i > nb_ports) || (r != LIBUSB_SUCCESS)) break; + memset(&conn_info, 0, sizeof(conn_info)); // For non HCDs, check if the node on this port is a hub or a regular device if (!is_hcd) { size = sizeof(USB_NODE_CONNECTION_INFORMATION); @@ -1071,6 +1072,7 @@ enum libusb_hid_report_type { found = false; for (i = 0; i<USB_MAXINTERFACES; i++) { + memset(&child_devinst, 0, sizeof(DEVINST)); // prevents /W4 warning if (i == 0) { r = CM_Get_Child(&child_devinst, devinst, 0); } else { @@ -1960,10 +1962,8 @@ static int windows_clock_gettime(int clk_id, struct timespec *tp) return LIBUSB_ERROR_OTHER; } } - default: - return LIBUSB_ERROR_INVALID_PARAM; } - return LIBUSB_ERROR_OTHER; + return LIBUSB_ERROR_INVALID_PARAM; } @@ -2921,7 +2921,7 @@ static int _hid_get_descriptor(struct hid_device_priv* dev, HANDLE hid_handle, i return LIBUSB_ERROR_INVALID_PARAM; case LIBUSB_DT_PHYSICAL: usbi_dbg("LIBUSB_DT_PHYSICAL"); - if (HidD_GetPhysicalDescriptor(hid_handle, data, (ULONG)size)) + if (HidD_GetPhysicalDescriptor(hid_handle, data, (ULONG)*size)) return LIBUSB_COMPLETED; return LIBUSB_ERROR_OTHER; } diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h index 3f1d121..e0ca419 100644 --- a/libusb/os/windows_usb.h +++ b/libusb/os/windows_usb.h @@ -20,6 +20,14 @@ #pragma once +#if defined(_MSC_VER) +// disable /W4 MSVC warnings that are benign +#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4100) // unreferenced formal parameter +#pragma warning(disable:4214) // bit field types other than int +#pragma warning(disable:4201) // nameless struct/union +#endif + // Windows API default is uppercase - ugh! #if !defined(bool) #define bool BOOL @@ -84,7 +92,7 @@ inline void upperize(char* str) { #define ERR_BUFFER_SIZE 256 // Handle code for HID interface that have been claimed ("dibs") -#define INTERFACE_CLAIMED ((HANDLE)0xD1B5) +#define INTERFACE_CLAIMED ((HANDLE)(LONG_PTR)0xD1B5) // Additional return code for HID operations that completed synchronously #define LIBUSB_COMPLETED (LIBUSB_SUCCESS + 1) @@ -597,23 +605,23 @@ typedef struct _USB_HUB_CAPABILITIES_EX { typedef ret (api * __dll_##name##_t)args; __dll_##name##_t name #define DLL_LOAD(dll, name, ret_on_failure) \ - do { \ - HMODULE h = GetModuleHandle(#dll); \ - if(!h) \ - h = LoadLibrary(#dll); \ - if(!h) { \ - if(ret_on_failure) \ - return LIBUSB_ERROR_OTHER; \ - else break; } \ - if((name = (__dll_##name##_t)GetProcAddress(h, #name))) \ - break; \ - if((name = (__dll_##name##_t)GetProcAddress(h, #name "A"))) \ - break; \ - if((name = (__dll_##name##_t)GetProcAddress(h, #name "W"))) \ - break; \ - if(ret_on_failure) \ - return LIBUSB_ERROR_OTHER; \ - } while(0) + do { \ + HMODULE h = GetModuleHandle(#dll); \ + if (!h) \ + h = LoadLibrary(#dll); \ + if (!h) { \ + if (ret_on_failure) { return LIBUSB_ERROR_OTHER; } \ + else { break; } \ + } \ + name = (__dll_##name##_t)GetProcAddress(h, #name); \ + if (name) break; \ + name = (__dll_##name##_t)GetProcAddress(h, #name "A"); \ + if (name) break; \ + name = (__dll_##name##_t)GetProcAddress(h, #name "W"); \ + if (name) break; \ + if(ret_on_failure) \ + return LIBUSB_ERROR_OTHER; \ + } while(0) /* winusb.dll interface */ |