mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
On overlapping buffers use memmove
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user