diff --git a/src/node_main.cc b/src/node_main.cc index 58e747e52c49ef..7cc5918b228ba8 100644 --- a/src/node_main.cc +++ b/src/node_main.cc @@ -3,7 +3,7 @@ #ifdef _WIN32 int wmain(int argc, wchar_t *wargv[]) { // Convert argv to to UTF8 - char** argv = new char*[argc]; + char** argv = new char*[argc + 1]; for (int i = 0; i < argc; i++) { // Compute the size of the required buffer DWORD size = WideCharToMultiByte(CP_UTF8, @@ -35,6 +35,7 @@ int wmain(int argc, wchar_t *wargv[]) { exit(1); } } + argv[argc] = nullptr; // Now that conversion is done, we can finally start. return node::Start(argc, argv); } diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index d1db3a815f5df5..e6a47a3175172e 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -40,11 +40,11 @@ child.exec(nodejs + ' --eval "console.error(42)"', assert.equal(stderr, ''); }); - child.exec(cmd + "'[]'", + child.exec(cmd + "'[]'", common.mustCall( function(err, stdout, stderr) { assert.equal(stdout, '[]\n'); assert.equal(stderr, ''); - }); + })); }); // assert that module loading works @@ -59,6 +59,12 @@ child.exec(nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"', assert.equal(status.code, 42); }); +// Missing argument should not crash +child.exec(nodejs + ' -e', common.mustCall(function(status, stdout, stderr) { + assert.notStrictEqual(status, null); + assert.strictEqual(status.code, 9); +})); + // empty program should do nothing child.exec(nodejs + ' -e ""', function(status, stdout, stderr) { assert.equal(stdout, '');