Browse Source

buffer: fix Buffer::Copy regression from 00b4b7b

If the end argument is omitted or not a number, make it default to
the end of the buffer, not zero.

Ideally, it should not matter what it defaults to because the JS shim
in lib/buffer.js should handle that but there are still several places
in node.js core that secrete SlowBuffers, hence Buffer::Copy() gets
called without going through Buffer.prototype.copy() first.
v0.9.9-release
Ben Noordhuis 12 years ago
parent
commit
2e371b8f92
  1. 3
      src/node_buffer.cc

3
src/node_buffer.cc

@ -403,7 +403,8 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
size_t target_length = Buffer::Length(target); size_t target_length = Buffer::Length(target);
size_t target_start = args[1]->Uint32Value(); size_t target_start = args[1]->Uint32Value();
size_t source_start = args[2]->Uint32Value(); size_t source_start = args[2]->Uint32Value();
size_t source_end = args[3]->Uint32Value(); size_t source_end = args[3]->IsUint32() ? args[3]->Uint32Value()
: source->length_;
if (source_end < source_start) { if (source_end < source_start) {
return ThrowRangeError("sourceEnd < sourceStart"); return ThrowRangeError("sourceEnd < sourceStart");

Loading…
Cancel
Save