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: nodejs#46223
  • Loading branch information
bnoordhuis committed Jan 20, 2023
1 parent babe6d7 commit 7325648
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 7325648

Please sign in to comment.