Skip to content

Commit e966d1f

Browse files
vkurchatkinjasnell
authored andcommitted
buffer: don't set kNoZeroFill flag in allocUnsafe
If `kNoZeroFill` is set here, it won't be reset in case of pooled allocation. In case of "slow" allocation it will be set later anyway. Fixes: #6006 PR-URL: #6007 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent 0605555 commit e966d1f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/buffer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ Buffer.alloc = function(size, fill, encoding) {
148148
Buffer.allocUnsafe = function(size) {
149149
if (typeof size !== 'number')
150150
throw new TypeError('"size" argument must be a number');
151-
if (size > 0)
152-
flags[kNoZeroFill] = 1;
153151
return allocate(size);
154152
};
155153

test/parallel/test-buffer-safe-unsafe.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ const safe = Buffer.alloc(10);
77

88
function isZeroFilled(buf) {
99
for (let n = 0; n < buf.length; n++)
10-
if (buf[n] > 0) return false;
10+
if (buf[n] !== 0) return false;
1111
return true;
1212
}
1313

1414
assert(isZeroFilled(safe));
15+
16+
// Test that unsafe allocations doesn't affect subsequent safe allocations
17+
Buffer.allocUnsafe(10);
18+
assert(isZeroFilled(new Float64Array(10)));
19+
20+
new Buffer(10);
21+
assert(isZeroFilled(new Float64Array(10)));
22+
23+
Buffer.allocUnsafe(10);
24+
assert(isZeroFilled(Buffer.alloc(10)));

0 commit comments

Comments
 (0)