Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use parent SlowBuffer, if any, when Buffer is sliced

Closes #3416
Closes #3477
  • Loading branch information...
commit 57d53a47e86c310f99e991ea0afb4a3790a54751 1 parent 81a889f
@Skomski Skomski authored piscisaureus committed
Showing with 8 additions and 1 deletion.
  1. +5 −1 lib/buffer.js
  2. +3 −0  test/simple/test-buffer.js
View
6 lib/buffer.js
@@ -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
View
3  test/simple/test-buffer.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.