From 19a458d5235e358ccb6f0b0d5777bb96afae46f6 Mon Sep 17 00:00:00 2001 From: Learath Date: Sat, 8 Dec 2018 00:24:57 +0100 Subject: [PATCH] Fix a couple issues --- src/base/system.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 3631d1b18..61356c429 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -175,22 +175,25 @@ static void logger_stdout_sync(const char *line, void *user) (void)user; size_t length = strlen(line); - wchar_t *wide = malloc(length * sizeof *wide); + wchar_t *wide = malloc(length * sizeof (*wide)); mem_zero(wide, length * sizeof *wide); const char *p = line; - int i = 0; - for(int codepoint = 0; (codepoint = str_utf8_decode(&p)); i++) + int wlen = 0; + for(int codepoint = 0; (codepoint = str_utf8_decode(&p)); wlen++) { + if(codepoint < 0) + return; + char u16[4] = {0}; if(str_utf16le_encode(u16, codepoint) != 2) return; - mem_copy(&wide[i], u16, 2); + mem_copy(&wide[wlen], u16, 2); } HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); - WriteConsoleW(console, wide, i, NULL, NULL); + WriteConsoleW(console, wide, wlen, NULL, NULL); WriteConsoleA(console, "\n", 1, NULL, NULL); } #endif