summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-06-25 23:54:05 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-28 15:04:44 +0000
commit3f8e0c31078d100da6218fed3f6635c65e032e3c (patch)
treeaf8b9014a00df8e317698565394c480aaec6e6de
parenteb4b6e8f3574296e1f864fc7a5dfdef147bc5839 (diff)
QVarLengthArray: fix aliasing error in insert(it, n, v)
Taking the copy after the resize is completely pointless: the copy is there to ensure that `t`, being a reference potentially aliasing an element in [begin(), end()[ before the resize(), isn't invalidated by the resize(), so it must be taken before resize(). Add a comment so the next rewrite doesn't cause this to be mixed up again. [ChangeLog][QtCore][QVarLengthArray] Fixed an aliasing bug affecting insertions of objects aliasing existing elements. Change-Id: I26bc449fa99bf8d09a19147a12a69ac4314cc61d Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit 6e57e41f9aef5ccfa122c10bc6253d47dafd93d2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/tools/qvarlengtharray.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 5738baae0c..24505d629b 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -647,8 +647,8 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
qsizetype offset = qsizetype(before - ptr);
if (n != 0) {
+ const T copy(t); // `t` could alias an element in [begin(), end()[
resize(s + n);
- const T copy(t);
if (!QTypeInfo<T>::isRelocatable) {
T *b = ptr + offset;
T *j = ptr + s;