Skip to content

Commit 3973354

Browse files
committed
benchmark: fix buffer-base64-decode.js
693401d added stricter range checking for buffer operations and that apparently seems to have uncovered the fact that one of our benchmarks was overflowing a buffer. Increase the buffer size so the benchmark doesn't throw an error anymore. PR-URL: #27260 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent f98679f commit 3973354

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

benchmark/buffers/buffer-base64-decode.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ const bench = common.createBenchmark(main, {
99

1010
function main({ n, size }) {
1111
const s = 'abcd'.repeat(size);
12+
const encodedSize = s.length * 3 / 4;
1213
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
1314
s.match(/./); // Flatten string.
1415
assert.strictEqual(s.length % 4, 0);
15-
const b = Buffer.allocUnsafe(s.length / 4 * 3);
16-
b.write(s, 0, s.length, 'base64');
16+
const b = Buffer.allocUnsafe(encodedSize);
17+
b.write(s, 0, encodedSize, 'base64');
1718
bench.start();
1819
for (var i = 0; i < n; i += 1) b.base64Write(s, 0, s.length);
1920
bench.end(n);

0 commit comments

Comments
 (0)