From 4dbd97c8f990e8ed5714cc2a599446920670e78d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 17 Feb 2023 15:36:51 +0100 Subject: [PATCH] q_uninitialized_relocate: use memcpy, not memmove 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 --- src/corelib/tools/qcontainertools_impl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index da35c511f90..f63a583d4cb 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -72,10 +72,10 @@ template void q_uninitialized_relocate_n(T* first, N n, T* out) { if constexpr (QTypeInfo::isRelocatable) { - if (n != N(0)) { // even if N == 0, out == nullptr or first == nullptr are UB for memmove() - std::memmove(static_cast(out), - static_cast(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(out), + static_cast(first), + n * sizeof(T)); } } else { q_uninitialized_move_if_noexcept_n(first, n, out);