GeezerVison is showing github.com — src: fix Windows segfault with `--eval` · nodejs/node@cd38401
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_main.cc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ int wmain(int argc, wchar_t *wargv[]) { | 11 | 11 | } | 12 | 12 |
| 13 | 13 | // Convert argv to to UTF8 | 14 | | - char** argv = new char*[argc]; | | 14 | + char** argv = new char*[argc + 1]; | 15 | 15 | for (int i = 0; i < argc; i++) { | 16 | 16 | // Compute the size of the required buffer | 17 | 17 | DWORD size = WideCharToMultiByte(CP_UTF8, | @@ -43,6 +43,7 @@ int wmain(int argc, wchar_t *wargv[]) { | 43 | 43 | exit(1); | 44 | 44 | } | 45 | 45 | } | | 46 | + argv[argc] = nullptr; | 46 | 47 | // Now that conversion is done, we can finally start. | 47 | 48 | return node::Start(argc, argv); | 48 | 49 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,11 +40,11 @@ child.exec(nodejs + ' --eval "console.error(42)"', | 40 | 40 | assert.equal(stderr, ''); | 41 | 41 | }); | 42 | 42 |
| 43 | | - child.exec(cmd + "'[]'", | | 43 | + child.exec(cmd + "'[]'", common.mustCall( | 44 | 44 | function(err, stdout, stderr) { | 45 | 45 | assert.equal(stdout, '[]\n'); | 46 | 46 | assert.equal(stderr, ''); | 47 | | - }); | | 47 | + })); | 48 | 48 | }); | 49 | 49 |
| 50 | 50 | // assert that module loading works | @@ -66,6 +66,12 @@ child.exec(nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"', | 66 | 66 | assert.equal(status.code, 42); | 67 | 67 | }); | 68 | 68 |
| | 69 | +// Missing argument should not crash | | 70 | +child.exec(nodejs + ' -e', common.mustCall(function(status, stdout, stderr) { | | 71 | + assert.notStrictEqual(status, null); | | 72 | + assert.strictEqual(status.code, 9); | | 73 | +})); | | 74 | + | 69 | 75 | // empty program should do nothing | 70 | 76 | child.exec(nodejs + ' -e ""', function(status, stdout, stderr) { | 71 | 77 | assert.equal(stdout, ''); | |
|