Skip to content

Commit

Permalink
src: fix c++ exception on bad command line arg
Browse files Browse the repository at this point in the history
Replace stoull() with strtoull(). The former throws an exception when
the input is malformed, the latter doesn't.

Fixes: #46223
PR-URL: #46290
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
bnoordhuis authored and ruyadorno committed Jan 31, 2023
1 parent 940484b commit fb7bee2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ void OptionsParser<Options>::Parse(
*Lookup<int64_t>(info.field, options) = std::atoll(value.c_str());
break;
case kUInteger:
*Lookup<uint64_t>(info.field, options) = std::stoull(value);
*Lookup<uint64_t>(info.field, options) =
std::strtoull(value.c_str(), nullptr, 10);
break;
case kString:
*Lookup<std::string>(info.field, options) = value;
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-cpu-prof-invalid-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ const {
}

// --cpu-prof-interval without --cpu-prof
{
for (const arg of [kCpuProfInterval, 'crashme']) {
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--cpu-prof-interval',
kCpuProfInterval,
arg,
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
Expand Down

0 comments on commit fb7bee2

Please sign in to comment.