Browse Source

Fix triple buffer slice bug

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
b8c0349750
  1. 2
      src/node_buffer.cc
  2. 11
      test/simple/test-buffer.js

2
src/node_buffer.cc

@ -163,7 +163,7 @@ Buffer::Buffer(Buffer *parent, size_t start, size_t end) : ObjectWrap() {
blob_ref(blob_); blob_ref(blob_);
assert(start <= end); assert(start <= end);
off_ = start; off_ = parent->off_ + start;
length_ = end - start; length_ = end - start;
assert(length_ <= parent->length_); assert(length_ <= parent->length_);

11
test/simple/test-buffer.js

@ -95,3 +95,14 @@ var slice = buffer.toString('utf8', 0, size);
assert.equal(slice, testValue); assert.equal(slice, testValue);
// Test triple slice
var a = new Buffer(8);
for (var i = 0; i < 8; i++) a[i] = i;
var b = a.slice(4,8);
assert.equal(4, b[0]);
assert.equal(5, b[1]);
assert.equal(6, b[2]);
assert.equal(7, b[3]);
var c = b.slice(2 , 4);
assert.equal(6, c[0]);
assert.equal(7, c[1]);

Loading…
Cancel
Save