function createPool() {
poolSize = Buffer.poolSize;
- flags[kNoZeroFill] = 1;
+ if (poolSize > 0)
+ flags[kNoZeroFill] = 1;
allocPool = new Uint8Array(poolSize);
Object.setPrototypeOf(allocPool, Buffer.prototype);
poolOffset = 0;
function SlowBuffer(length) {
if (+length != length)
length = 0;
- flags[kNoZeroFill] = 1;
+ if (length > 0)
+ flags[kNoZeroFill] = 1;
const ui8 = new Uint8Array(+length);
Object.setPrototypeOf(ui8, Buffer.prototype);
return ui8;
function allocate(size) {
- if (size === 0)
- return SlowBuffer(0);
+ if (size === 0) {
+ const ui8 = new Uint8Array(size);
+ Object.setPrototypeOf(ui8, Buffer.prototype);
+ return ui8;
+ }
if (size < (Buffer.poolSize >>> 1)) {
if (size > (poolSize - poolOffset))
createPool();
alignPool();
return b;
} else {
- flags[kNoZeroFill] = 1;
+ // Even though this is checked above, the conditional is a safety net and
+ // sanity check to prevent any subsequent typed array allocation from not
+ // being zero filled.
+ if (size > 0)
+ flags[kNoZeroFill] = 1;
const ui8 = new Uint8Array(size);
Object.setPrototypeOf(ui8, Buffer.prototype);
return ui8;
--- /dev/null
+'use strict';
+
+require('../common');
+const assert = require('assert');
+
+
+function testUint8Array(ui) {
+ const length = ui.length;
+ for (let i = 0; i < length; i++)
+ if (ui[i] !== 0) return false;
+ return true;
+}
+
+
+for (let i = 0; i < 100; i++) {
+ new Buffer(0);
+ let ui = new Uint8Array(65);
+ assert.ok(testUint8Array(ui), 'Uint8Array is not zero-filled');
+}