Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3ab106

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
buffer: remove obsolete NaN check
These two NaN entries are not necessary and we can safely remove them. PR-URL: #18744 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent ed55374 commit f3ab106
Copy full SHA for f3ab106

File tree

Expand file treeCollapse file tree

2 files changed

+5
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-5
lines changed
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
377377
} else {
378378
// convert length to non-negative integer
379379
length = +length;
380-
// Check for NaN
381-
if (length !== length) {
382-
length = 0;
383-
} else if (length > 0) {
380+
if (length > 0) {
384381
if (length > maxLength)
385382
throw new errors.RangeError('ERR_BUFFER_OUT_OF_BOUNDS', 'length');
386383
} else {
@@ -403,7 +400,7 @@ function fromObject(obj) {
403400
}
404401

405402
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
406-
if (typeof obj.length !== 'number' || obj.length !== obj.length) {
403+
if (typeof obj.length !== 'number') {
407404
return new FastBuffer();
408405
}
409406
return fromArrayLike(obj);
Collapse file

‎test/parallel/test-buffer-arraybuffer.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-arraybuffer.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,6 @@ b.writeDoubleBE(11.11, 0, true);
148148
message: '"length" is outside of buffer bounds'
149149
});
150150
}
151+
152+
// Test an array like entry with the length set to NaN.
153+
assert.deepStrictEqual(Buffer.from({ length: NaN }), Buffer.alloc(0));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.