diff options
-rw-r--r-- | lib/buffer.js | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index 0df3ab297e..05e0b74033 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -836,8 +836,8 @@ Buffer.prototype.write = function(string, offset, length, encoding) { Buffer.prototype.toJSON = function() { - if (this.length) { - const data = []; + if (this.length > 0) { + const data = new Array(this.length); for (var i = 0; i < this.length; ++i) data[i] = this[i]; return { type: 'Buffer', data }; |