diff --git a/examples/xusb.c b/examples/xusb.c index 8e09e052..0eafd8c3 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -935,7 +935,10 @@ int main(int argc, char** argv) break; case 'b': if (j+1 < argc) { - strncpy(binary_name, argv[j+1], 64); + // WDK's OACR doesn't like strncpy... + for (i=0; (i<(sizeof(binary_name)-1)) && (argv[j+1][i] != 0); i++) + binary_name[i] = argv[j+1][i]; + binary_name[i] = 0; j++; } binary_dump = true; diff --git a/libusb/core.c b/libusb/core.c index dd352f95..82cf782f 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1611,7 +1611,7 @@ void API_EXPORTED libusb_set_debug(libusb_context *ctx, int level) */ int API_EXPORTED libusb_init(libusb_context **context) { - char *dbg = getenv("LIBUSB_DEBUG"); + char *dbg; struct libusb_context *ctx; int r = 0; @@ -1639,6 +1639,7 @@ int API_EXPORTED libusb_init(libusb_context **context) ctx->debug = LOG_LEVEL_DEBUG; #endif + dbg = getenv("LIBUSB_DEBUG"); if (dbg) { ctx->debug = atoi(dbg); if (ctx->debug) @@ -1774,21 +1775,21 @@ int API_EXPORTED libusb_has_capability(uint32_t capability) #define _W32_FT_OFFSET (116444736000000000) int usbi_gettimeofday(struct timeval *tp, void *tzp) - { - union { - unsigned __int64 ns100; /*time since 1 Jan 1601 in 100ns units */ - FILETIME ft; - } _now; +{ + union { + unsigned __int64 ns100; /* Time since 1 Jan 1601, in 100ns units */ + FILETIME ft; + } _now; + UNUSED(tzp); - if(tp) - { - GetSystemTimeAsFileTime (&_now.ft); - tp->tv_usec=(long)((_now.ns100 / 10) % 1000000 ); - tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000); - } - /* Always return 0 as per Open Group Base Specifications Issue 6. - Do not set errno on error. */ - return 0; + if(tp) { + GetSystemTimeAsFileTime (&_now.ft); + tp->tv_usec=(long)((_now.ns100 / 10) % 1000000 ); + tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000); + } + /* Always return 0 as per Open Group Base Specifications Issue 6. + Do not set errno on error. */ + return 0; } #endif diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 41a6bf0c..27362f70 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -49,6 +49,9 @@ #define USB_MAXINTERFACES 32 #define USB_MAXCONFIG 8 +/* The following is used to silence warnings for unused variables */ +#define UNUSED(var) (void)sizeof(var) + struct list_head { struct list_head *prev, *next; }; diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index e7bd8c55..4601a79d 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -139,7 +139,7 @@ void init_polling(void) } is_polling_set = TRUE; } - compat_spinlock = 0; + InterlockedExchange((LONG *)&compat_spinlock, 0); } // Internal function to retrieve the table index (and lock the fd mutex) @@ -237,7 +237,7 @@ void exit_polling(void) DeleteCriticalSection(&_poll_fd[i].mutex); } } - compat_spinlock = 0; + InterlockedExchange((LONG *)&compat_spinlock, 0); } /* @@ -672,6 +672,7 @@ int usbi_close(int fd) ssize_t usbi_write(int fd, const void *buf, size_t count) { int _index; + UNUSED(buf); CHECK_INIT_POLLING; @@ -708,6 +709,7 @@ ssize_t usbi_read(int fd, void *buf, size_t count) { int _index; ssize_t r = -1; + UNUSED(buf); CHECK_INIT_POLLING; diff --git a/libusb/os/threads_windows.c b/libusb/os/threads_windows.c index 4acfff69..aa05edc6 100644 --- a/libusb/os/threads_windows.c +++ b/libusb/os/threads_windows.c @@ -28,6 +28,7 @@ int usbi_mutex_init(usbi_mutex_t *mutex, const usbi_mutexattr_t *attr) { + UNUSED(attr); if(! mutex) return ((errno=EINVAL)); *mutex = CreateMutex(NULL, FALSE, NULL); if(!*mutex) return ((errno=ENOMEM)); @@ -83,6 +84,7 @@ int usbi_mutex_static_unlock(usbi_mutex_static_t *mutex) { int usbi_cond_init(usbi_cond_t *cond, const usbi_condattr_t *attr) { + UNUSED(attr); if(!cond) return ((errno=EINVAL)); list_init(&cond->waiters ); list_init(&cond->not_waiting); diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 9b30e2d0..3b90d18b 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -38,11 +38,6 @@ #include "poll_windows.h" #include "windows_usb.h" -// The following prevents "banned API" errors when using the MS's WDK OACR/Prefast -#if defined(_PREFAST_) -#pragma warning(disable:28719) -#endif - // The 2 macros below are used in conjunction with safe loops. #define LOOP_CHECK(fcall) { r=fcall; if (r != LIBUSB_SUCCESS) continue; } #define LOOP_BREAK(err) { r=err; continue; } @@ -455,7 +450,7 @@ static unsigned long htab_hash(char* str) char* sz = str; // Compute main hash value (algorithm suggested by Nokia) - while ((c = *sz++)) + while ((c = *sz++) != 0) r = ((r << 5) + r) + c; if (r == 0) ++r; @@ -1193,6 +1188,8 @@ static int set_composite_interface(struct libusb_context* ctx, struct libusb_dev priv->usb_interface[interface_number].apib = &usb_api_backend[api]; if ((api == USB_API_HID) && (priv->hid == NULL)) { priv->hid = calloc(1, sizeof(struct hid_device_priv)); + if (priv->hid == NULL) + return LIBUSB_ERROR_NO_MEM; } priv->composite_api_flags |= 1<= 2) + break; } // Read the Device ID path. This is what we'll use as UID diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 217b1bd9..071c2efd 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10534 +#define LIBUSB_NANO 10535 diff --git a/msvc/config.h b/msvc/config.h index e14d91d0..e221bab8 100644 --- a/msvc/config.h +++ b/msvc/config.h @@ -5,6 +5,15 @@ #error "Please make sure the msvc/ directory is removed from your build path." #endif +/* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */ +#pragma warning(disable:4200) +#if defined(_PREFAST_) +/* Disable "Banned API" errors when using the MS's WDK OACR/Prefast */ +#pragma warning(disable:28719) +/* Disable "The function 'InitializeCriticalSection' must be called from within a try/except block" */ +#pragma warning(disable:28125) +#endif + /* Default visibility */ #define DEFAULT_VISIBILITY /**/ diff --git a/msvc/libusb_dll.vcxproj b/msvc/libusb_dll.vcxproj index 521c6139..f1881fe6 100644 --- a/msvc/libusb_dll.vcxproj +++ b/msvc/libusb_dll.vcxproj @@ -79,7 +79,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDebugDLL - Level3 + Level4 ProgramDatabase @@ -98,7 +98,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_WIN64;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDebugDLL - Level3 + Level4 ProgramDatabase @@ -113,7 +113,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL - Level3 + Level4 $(OutDir)libusb-1.0.dll @@ -129,7 +129,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_WIN64;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL - Level3 + Level4 $(OutDir)libusb-1.0.dll diff --git a/msvc/libusb_static.vcxproj b/msvc/libusb_static.vcxproj index 9cb482d5..57254be1 100644 --- a/msvc/libusb_static.vcxproj +++ b/msvc/libusb_static.vcxproj @@ -79,7 +79,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDebug - Level3 + Level4 ProgramDatabase @@ -95,7 +95,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_WIN64;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDebug - Level3 + Level4 ProgramDatabase @@ -107,7 +107,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreaded - Level3 + Level4 $(OutDir)libusb-1.0.lib @@ -121,7 +121,7 @@ .;..\libusb;%(AdditionalIncludeDirectories) _WIN32;_WIN64;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreaded - Level3 + Level4 $(OutDir)libusb-1.0.lib