Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Otrishko <shishugi@gmail.com>2020-01-30 17:37:02 +0300
committerAnna Henningsen <anna@addaleax.net>2020-02-02 16:12:23 +0300
commitaec9ad8f6c8a75518d81279ec5e7188348e508de (patch)
tree9163973849f3ee4442481550cad20c9388dbb314 /src/debug_utils.cc
parentdbe881b64ce74f437ace5c6a884dfac5df597df2 (diff)
src: fix console debug output on Windows
The FWrite function on Windows assumed that MultiByteToWideChar automatically null-terminates the resulting string, but it will only do so if the size of the source was passed as -1 or null character was explicitly counted in the size. The FWrite uses std::string and its `.size()` method which doesn't count the null character even though the `.data()` method adds it to the resulting string. https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar#remarks > MultiByteToWideChar does not null-terminate an output string if the input string length is explicitly specified without a terminating null character. To null-terminate an output string for this function, the application should pass in -1 or explicitly count the terminating null character for the input string. PR-URL: https://github.com/nodejs/node/pull/31580 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/debug_utils.cc')
-rw-r--r--src/debug_utils.cc4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/debug_utils.cc b/src/debug_utils.cc
index 8f1e6aa3e6f..984c04eb2d3 100644
--- a/src/debug_utils.cc
+++ b/src/debug_utils.cc
@@ -468,9 +468,7 @@ void FWrite(FILE* file, const std::string& str) {
std::vector<wchar_t> wbuf(n);
MultiByteToWideChar(CP_UTF8, 0, str.data(), str.size(), wbuf.data(), n);
- // Don't include the final null character in the output
- CHECK_GT(n, 0);
- WriteConsoleW(handle, wbuf.data(), n - 1, nullptr, nullptr);
+ WriteConsoleW(handle, wbuf.data(), n, nullptr, nullptr);
return;
#elif defined(__ANDROID__)
if (file == stderr) {