Skip to content

Commit

Permalink
q_uninitialized_relocate: use memcpy, not memmove
Browse files Browse the repository at this point in the history
The [first, first+n) and [out, out+n) ranges cannot possibly overlap, as
by definition the former contains live objects while the latter points
into uninitialized storage. So we can use memcpy here, and not memmove.

Change-Id: I4a1b39f73ffa67915c5252938554f45f4444293e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
dangelog committed Feb 17, 2023
1 parent eb46412 commit 4dbd97c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/corelib/tools/qcontainertools_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ template <typename T, typename N>
void q_uninitialized_relocate_n(T* first, N n, T* out)
{
if constexpr (QTypeInfo<T>::isRelocatable) {
if (n != N(0)) { // even if N == 0, out == nullptr or first == nullptr are UB for memmove()
std::memmove(static_cast<void*>(out),
static_cast<const void*>(first),
n * sizeof(T));
if (n != N(0)) { // even if N == 0, out == nullptr or first == nullptr are UB for memcpy()
std::memcpy(static_cast<void *>(out),
static_cast<const void *>(first),
n * sizeof(T));
}
} else {
q_uninitialized_move_if_noexcept_n(first, n, out);
Expand Down

0 comments on commit 4dbd97c

Please sign in to comment.