From 09f861f231e6421f6f7cd8f8de4f3a05df8b204f 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 06ce9ca6d0c..5cab485bbd7 100644 --- a/src/node.cc +++ b/src/node.cc @@ -257,7 +257,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