assert.throws(function() { var len = 0xfffff; var sbuf = new SlowBuffer(len); var buf = new Buffer(sbuf, len, 0); SlowBuffer.makeFastBuffer(sbuf, buf, -len, len); // Should throw. for (var i = 0; i < len; ++i) buf[i] = 0x42; // Try to force segfault. }, RangeError);
function FastBuffer (length) { this.length = length; if (length > POOLSIZE) { // Big buffer, just alloc one. this.parent = new Buffer(length); this.offset = 0; } else { // Small buffer. if (!pool || pool.length - pool.used < length) allocPool(); this.parent = pool; this.offset = pool.used; pool.used += length; } // HERE HERE HERE SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length); }