Skip to content

Commit

Permalink
perf_hooks: fix checking range of options.figures in createHistogram
Browse files Browse the repository at this point in the history
For `options.figures`, number between 1 and 5 is allowed. So need
to use `validateInteger` to limit max as 5.

Refs: https://github.com/nodejs/node/blob/main/doc/api/perf_hooks.md#perf_hookscreatehistogramoptions
  • Loading branch information
deokjinkim committed Dec 28, 2022
1 parent 34af1f6 commit e239c68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/histogram.js
Expand Up @@ -368,7 +368,7 @@ function createHistogram(options = kEmptyObject) {
} else if (highest < 2n * lowest) {
throw new ERR_INVALID_ARG_VALUE.RangeError('options.highest', highest);
}
validateUint32(figures, 'options.figures', 1, 5);
validateInteger(figures, 'options.figures', 1, 5);
return internalRecordableHistogram(new _Histogram(lowest, highest, figures));
}

Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-perf-hooks-histogram.js
Expand Up @@ -135,6 +135,13 @@ const { inspect } = require('util');
});
});

// Number greater than 5 is not allowed
for (const i of [6, 10]) {
throws(() => createHistogram({ figures: i }), {
code: 'ERR_OUT_OF_RANGE',
});
}

createHistogram({ lowest: 1, highest: 11, figures: 1 });
}

Expand Down

0 comments on commit e239c68

Please sign in to comment.