From 606deecd16675707a8224795c5a34cd9b0d59b1f Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sat, 16 Jul 2016 20:06:47 +0300 Subject: [PATCH] src: don't include a null character in the WriteConsoleW call Fixes: https://github.com/nodejs/node/issues/7755 PR-URL: https://github.com/nodejs/node/pull/7764 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- src/node.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 00ab762b4b..23b1009616 100644 --- a/src/node.cc +++ b/src/node.cc @@ -192,7 +192,10 @@ static void PrintErrorString(const char* format, ...) { std::vector wbuf(n); MultiByteToWideChar(CP_UTF8, 0, out.data(), -1, wbuf.data(), n); - WriteConsoleW(stderr_handle, wbuf.data(), n, nullptr, nullptr); + + // Don't include the null character in the output + CHECK_GT(n, 0); + WriteConsoleW(stderr_handle, wbuf.data(), n - 1, nullptr, nullptr); #else vfprintf(stderr, format, ap); #endif