Skip to content

Commit

Permalink
fs: add validateBuffer to improve error
Browse files Browse the repository at this point in the history
PR-URL: #44769
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Hirotaka Tagawa / wafuwafu13 committed Sep 28, 2022
1 parent 8ec7bfd commit bb4891d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fs.js
Expand Up @@ -632,7 +632,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
}
({
offset = 0,
length = buffer.byteLength - offset,
length = buffer?.byteLength - offset,
position = null,
} = params ?? kEmptyObject);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read.js
Expand Up @@ -79,7 +79,7 @@ assert.throws(

assert.throws(
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
/TypeError: Cannot read properties of null \(reading 'byteLength'\)/,
{ code: 'ERR_INVALID_ARG_TYPE' },
'throws when options.buffer is null'
);

Expand Down

0 comments on commit bb4891d

Please sign in to comment.