From b8c0349750a09b10245d633826e75c0c5d135039 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 14 Apr 2010 00:36:34 -0700 Subject: [PATCH] Fix triple buffer slice bug --- src/node_buffer.cc | 2 +- test/simple/test-buffer.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index f524778f46..b9d74606ef 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -163,7 +163,7 @@ Buffer::Buffer(Buffer *parent, size_t start, size_t end) : ObjectWrap() { blob_ref(blob_); assert(start <= end); - off_ = start; + off_ = parent->off_ + start; length_ = end - start; assert(length_ <= parent->length_); diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 084c268ad6..17d6f08d56 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -95,3 +95,14 @@ var slice = buffer.toString('utf8', 0, size); 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]);