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: https://github.com/nodejs/node/issues/6006 PR-URL: https://github.com/nodejs/node/pull/6007 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
This commit is contained in:
parent
0928584444
commit
0dcb026db3
@ -163,8 +163,6 @@ Buffer.alloc = function(size, fill, encoding) {
|
|||||||
Buffer.allocUnsafe = function(size) {
|
Buffer.allocUnsafe = function(size) {
|
||||||
if (typeof size !== 'number')
|
if (typeof size !== 'number')
|
||||||
throw new TypeError('"size" argument must be a number');
|
throw new TypeError('"size" argument must be a number');
|
||||||
if (size > 0)
|
|
||||||
flags[kNoZeroFill] = 1;
|
|
||||||
return allocate(size);
|
return allocate(size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,8 +7,18 @@ const safe = Buffer.alloc(10);
|
|||||||
|
|
||||||
function isZeroFilled(buf) {
|
function isZeroFilled(buf) {
|
||||||
for (let n = 0; n < buf.length; n++)
|
for (let n = 0; n < buf.length; n++)
|
||||||
if (buf[n] > 0) return false;
|
if (buf[n] !== 0) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(isZeroFilled(safe));
|
assert(isZeroFilled(safe));
|
||||||
|
|
||||||
|
// Test that unsafe allocations doesn't affect subsequent safe allocations
|
||||||
|
Buffer.allocUnsafe(10);
|
||||||
|
assert(isZeroFilled(new Float64Array(10)));
|
||||||
|
|
||||||
|
new Buffer(10);
|
||||||
|
assert(isZeroFilled(new Float64Array(10)));
|
||||||
|
|
||||||
|
Buffer.allocUnsafe(10);
|
||||||
|
assert(isZeroFilled(Buffer.alloc(10)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user