Skip to content

Commit e239c68

Browse files
committed
perf_hooks: fix checking range of options.figures in createHistogram
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
1 parent 34af1f6 commit e239c68

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/internal/histogram.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function createHistogram(options = kEmptyObject) {
368368
} else if (highest < 2n * lowest) {
369369
throw new ERR_INVALID_ARG_VALUE.RangeError('options.highest', highest);
370370
}
371-
validateUint32(figures, 'options.figures', 1, 5);
371+
validateInteger(figures, 'options.figures', 1, 5);
372372
return internalRecordableHistogram(new _Histogram(lowest, highest, figures));
373373
}
374374

test/parallel/test-perf-hooks-histogram.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ const { inspect } = require('util');
135135
});
136136
});
137137

138+
// Number greater than 5 is not allowed
139+
for (const i of [6, 10]) {
140+
throws(() => createHistogram({ figures: i }), {
141+
code: 'ERR_OUT_OF_RANGE',
142+
});
143+
}
144+
138145
createHistogram({ lowest: 1, highest: 11, figures: 1 });
139146
}
140147

0 commit comments

Comments
 (0)