Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Use parent SlowBuffer, if any, when Buffer is sliced
Browse files Browse the repository at this point in the history
Closes #3416
Closes #3477
  • Loading branch information
skomski authored and piscisaureus committed Jun 20, 2012
1 parent 81a889f commit 57d53a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/buffer.js
Expand Up @@ -210,8 +210,12 @@ function Buffer(subject, encoding, offset) {

// Are we slicing?
if (typeof offset === 'number') {
if (!Buffer.isBuffer(subject)) {
throw new Error('First argument must be a Buffer when slicing');
}

this.length = coerce(encoding);
this.parent = subject;
this.parent = subject.parent ? subject.parent : subject;
this.offset = offset;
} else {
// Find the length
Expand Down
3 changes: 3 additions & 0 deletions test/simple/test-buffer.js
Expand Up @@ -724,3 +724,6 @@ var a = Buffer(3);
var b = Buffer('xxx');
a.write('aaaaaaaa', 'base64');
assert.equal(b.toString(), 'xxx');

// issue GH-3416
Buffer(Buffer(0), 0, 0);

0 comments on commit 57d53a4

Please sign in to comment.