summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-09 22:53:48 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-11 22:12:34 +0000
commit63f62bcd9a20ac1a844daa90b2770bf7f582240c (patch)
treea78777f384e77ceb050a22fc65c577916be82f80
parenta948c725e548c3b57f77a2916ce035528e82a843 (diff)
downloadqtbase-63f62bcd9a20ac1a844daa90b2770bf7f582240c.tar.gz
QVarLengthArray: assert that the range passed to erase() is valid
We already checked that the two iterators, indvidually, are valid, but we didn't check that the range formed by them is valid, namely that the end iterator is reachable from the start iterator. Add an assert, because if the range isn't valid, we run into UB in the std::move() algorithm two lines later. Qt 5.15 uses std::copy() here, which has the same precondition, so the assertion would make sense there, too. Change-Id: I90b7e846455ff86383a8971bea908036684961d8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit c38639089f0e17a3da40dca03fecac88f5d89ba9) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/tools/qvarlengtharray.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 125012e54b..248f90af01 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -541,6 +541,8 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
if (n == 0) // avoid UB in std::copy() below
return data() + f;
+ Q_ASSERT(n > 0); // aend must be reachable from abegin
+
if (QTypeInfo<T>::isComplex) {
std::copy(ptr + l, ptr + s, QT_MAKE_CHECKED_ARRAY_ITERATOR(ptr + f, s - f));
T *i = ptr + s;