diff options
| author | Denys Otrishko <shishugi@gmail.com> | 2020-01-30 16:37:02 +0200 |
|---|---|---|
| committer | Anna Henningsen <anna@addaleax.net> | 2020-02-02 14:12:23 +0100 |
| commit | aec9ad8f6c8a75518d81279ec5e7188348e508de (patch) | |
| tree | 9163973849f3ee4442481550cad20c9388dbb314 /src/debug_utils.cc | |
| parent | dbe881b64ce74f437ace5c6a884dfac5df597df2 (diff) | |
| download | node-new-aec9ad8f6c8a75518d81279ec5e7188348e508de.tar.gz | |
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.cc | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/debug_utils.cc b/src/debug_utils.cc index 8f1e6aa3e6..984c04eb2d 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) { |
