From 147093edd9c8c1bd2a9fdda76c40f5aba378222b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 30 Nov 2021 16:36:36 +0100 Subject: [PATCH] QVarLengthArray: More Self-Encapsulate Field Two more instances where we can use public API instead of accessing the data members directly. Amends 9d79e5f26ca58e7ddbb6367de044d05192107a4d. Task-number: QTBUG-84785 Change-Id: I2037339383836b0d292b3362fe1d6b056638e81a Reviewed-by: Fabian Kosmale Reviewed-by: Qt CI Bot --- src/corelib/tools/qvarlengtharray.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 18066a80ef..47062fc788 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -140,7 +140,7 @@ public: ptr = std::exchange(other.ptr, otherInlineStorage); } else { // inline storage: move into our storage (doesn't matter whether inline or external) - QtPrivate::q_uninitialized_relocate_n(other.ptr, other.s, data()); + QtPrivate::q_uninitialized_relocate_n(other.data(), other.size(), data()); } s = std::exchange(other.s, 0); return *this; @@ -550,8 +550,10 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::reallocate(qsizetype asi if (QTypeInfo::isComplex) { // call default constructor for new objects (which can throw) - while (s < asize) - new (ptr+(s++)) T; + while (size() < asize) { + new (data() + size()) T; + ++s; + } } else { s = asize; }