Browse Source

Use parent SlowBuffer, if any, when Buffer is sliced

Closes #3416
Closes #3477
v0.9.1-release
Karl Skomski 13 years ago
committed by Bert Belder
parent
commit
57d53a47e8
  1. 6
      lib/buffer.js
  2. 3
      test/simple/test-buffer.js

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

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);

Loading…
Cancel
Save