buffer: don't set zero fill for zero-length buffer
authorTrevor Norris <trev.norris@gmail.com>
Thu, 17 Sep 2015 16:48:16 +0000 (10:48 -0600)
committerJeremiah Senkpiel <fishrock123@rocketmail.com>
Sun, 20 Sep 2015 17:31:25 +0000 (10:31 -0700)
commitd63e02e08dd4217a9e6cdf611e42438b31b0d1be
tree922d09e9578c5fde7cd333b10686b0eaf4fba91f
parentb2ddf0f9a233f8f59da748166d434217db3dfa9a
buffer: don't set zero fill for zero-length buffer

Instantiating a Buffer of length zero would set the kNoZeroFill flag to
true but never actually call ArrayBuffer::Allocator(). Which means the
flag was never set back to false. The result was that the next
allocation would unconditionally not be zero filled.

Add test to ensure Uint8Array's are zero-filled after creating a Buffer
of length zero. This test may falsely succeed, but will not falsely fail.

Fix: https://github.com/nodejs/node/issues/2930
PR-URL: https://github.com/nodejs/node/pull/2931
Reviewed-By: Rod Vagg <rod@vagg.org>
lib/buffer.js
test/parallel/test-buffer-zero-fill-reset.js [new file with mode: 0644]