summaryrefslogtreecommitdiff
path: root/src/node_buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r--src/node_buffer.cc21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 9a13b1ef64..5253b04f92 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -298,7 +298,7 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
ssize_t target_start = args[1]->Int32Value();
ssize_t source_start = args[2]->Int32Value();
ssize_t source_end = args[3]->IsInt32() ? args[3]->Int32Value()
- : (source->length() - 1);
+ : source->length();
if (source_end < source_start) {
return ThrowException(Exception::Error(String::New(
@@ -315,24 +315,17 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
"sourceStart out of bounds")));
}
- if (source_end < 0 || source_end >= source->length()) {
+ if (source_end < 0 || source_end > source->length()) {
return ThrowException(Exception::Error(String::New(
"sourceEnd out of bounds")));
}
- ssize_t to_copy = MIN( (source_end - source_start + 1),
- (target->length() - target_start) );
+ ssize_t to_copy = MIN(source_end - source_start,
+ target->length() - target_start);
- if (source->handle_->StrictEquals(target->handle_)) {
- // need to use slightly slower memmove is the ranges might overlap
- memmove((void*)(target->data() + target_start),
- (const void*)(source->data() + source_start),
- to_copy);
- } else {
- memcpy((void*)(target->data() + target_start),
- (const void*)(source->data() + source_start),
- to_copy);
- }
+ memcpy((void*)(target->data() + target_start),
+ (const void*)(source->data() + source_start),
+ to_copy);
return scope.Close(Integer::New(to_copy));
}