windows: Improved log message output to MSVC
authordmitrykos <dmitrykos@neutroncode.com>
Thu, 31 Jan 2019 21:17:06 +0000 (23:17 +0200)
committerNathan Hjelm <hjelmn@me.com>
Fri, 5 Apr 2019 04:35:03 +0000 (22:35 -0600)
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 <hjelmn@me.com>
libusb/core.c
libusb/version_nano.h

index 8823b19..ddba089 100644 (file)
@@ -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) {
index 25c45e5..aefd792 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11358
+#define LIBUSB_NANO 11359