From 542e6fd03d115b74a9aa3ebea1d21d63e4a86aa1 Mon Sep 17 00:00:00 2001 From: dmitrykos Date: Thu, 31 Jan 2019 23:17:06 +0200 Subject: windows: Improved log message output to MSVC Improved log message output to MSVC handling by converting multi-byte string (assumed to be UTF-8) to WCHAR string if UNICODE is defined, if UNICODE is not defined then multi-byte string is sent to MSVC (Windows CE defines UNICODE always, so it will use UNICODE case), added check for 0 to avoid sending trash to MSVC (and possibly crash the process) if conversion to WCHAR string fails. Closes #504 Signed-off-by: Nathan Hjelm --- libusb/core.c | 11 ++++++----- libusb/version_nano.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index 8823b19..ddba089 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -2480,13 +2480,14 @@ int usbi_vsnprintf(char *str, size_t size, const char *format, va_list ap) static void usbi_log_str(enum libusb_log_level level, const char *str) { #if defined(USE_SYSTEM_LOGGING_FACILITY) -#if defined(OS_WINDOWS) +#if defined(OS_WINDOWS) || defined(OS_WINCE) +#if !defined(UNICODE) OutputDebugStringA(str); -#elif defined(OS_WINCE) - /* Windows CE only supports the Unicode version of OutputDebugString. */ +#else WCHAR wbuf[USBI_MAX_LOG_LEN]; - MultiByteToWideChar(CP_UTF8, 0, str, -1, wbuf, sizeof(wbuf)); - OutputDebugStringW(wbuf); + if (MultiByteToWideChar(CP_UTF8, 0, str, -1, wbuf, sizeof(wbuf)) != 0) + OutputDebugStringW(wbuf); +#endif #elif defined(__ANDROID__) int priority = ANDROID_LOG_UNKNOWN; switch (level) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 25c45e5..aefd792 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11358 +#define LIBUSB_NANO 11359 -- cgit v1.2.1