Permalink
Browse files

On overlapping buffers use memmove

  • Loading branch information...
1 parent 898afba commit 02ed0ec93bc8f6bcd7f1d629dca64ba1f335ea05 @mranney mranney committed with ry Jun 30, 2010
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/node_buffer.cc
View
@@ -323,9 +323,16 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
ssize_t to_copy = MIN(source_end - source_start,
target->length() - target_start);
- memcpy((void*)(target->data() + target_start),
- (const void*)(source->data() + source_start),
- to_copy);
+ if (target->blob_ == source->blob_) {
+ // 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);
+ }
return scope.Close(Integer::New(to_copy));
}

0 comments on commit 02ed0ec

Please sign in to comment.