Skip to content

Commit 4c207d9

Browse files
committed
test: do not use uninitialized memory in common flags check
Only use the amount of data that was actually read from the test file. Otherwise, there is a small risk of getting false positives, and generally reading uninitialized memory makes using automated memory error detection tools harder. PR-URL: #25475 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 688fb8d commit 4c207d9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/common/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ if (process.argv.length === 2 &&
5757
const bytesToRead = 1500;
5858
const buffer = Buffer.allocUnsafe(bytesToRead);
5959
const fd = fs.openSync(module.parent.filename, 'r');
60-
fs.readSync(fd, buffer, 0, bytesToRead);
60+
const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead);
6161
fs.closeSync(fd);
62-
const source = buffer.toString();
62+
const source = buffer.toString('utf8', 0, bytesRead);
6363

6464
const flagStart = source.indexOf('// Flags: --') + 10;
6565
if (flagStart !== 9) {

0 commit comments

Comments
 (0)