From e108ff4da7cd18d3b48cc6e769ae04c9578f7a8b Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Sat, 8 Mar 2014 18:52:51 +0400 Subject: [PATCH] buffer: fix typo in `SlowBuffer` --- lib/buffer.js | 2 +- test/simple/test-buffer.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 084d96f..cd9592d 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -93,7 +93,7 @@ function Buffer(subject, encoding) { function SlowBuffer(length) { length = length >>> 0; - if (this.length > kMaxLength) { + if (length > kMaxLength) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength.toString(16) + ' bytes'); } diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 55a5ca7..a13bb22 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -24,6 +24,7 @@ var assert = require('assert'); var Buffer = require('buffer').Buffer; var SlowBuffer = require('buffer').SlowBuffer; +var smalloc = require('smalloc'); // counter to ensure unique value is always copied var cntr = 0; @@ -993,3 +994,12 @@ for (var i = 0; i < 5; i++) b.fill('ghijk'); for (var i = 0; i < 5; i++) assert.notEqual(d[i], b[i]); + + +assert.throws(function () { + new Buffer(smalloc.kMaxLength + 1); +}, RangeError); + +assert.throws(function () { + new SlowBuffer(smalloc.kMaxLength + 1); +}, RangeError); -- 2.7.4