summaryrefslogtreecommitdiffstats
path: root/src/corelib
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 17:27:05 +0100
commitc38639089f0e17a3da40dca03fecac88f5d89ba9 (patch)
treef26c95e673bfa6a913ab43447f58c05edf1aa4bc /src/corelib
parent7670db3146c402ddb322887976a6edf639ed9a71 (diff)
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. Pick-to: 6.2 5.15 Change-Id: I90b7e846455ff86383a8971bea908036684961d8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-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 07add066af..8b92ded0e3 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -896,6 +896,8 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::erase(const_iterator abegin, const_iterat
if (n == 0) // avoid UB in std::move() below
return data() + f;
+ Q_ASSERT(n > 0); // aend must be reachable from abegin
+
if constexpr (QTypeInfo<T>::isComplex) {
std::move(begin() + l, end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin() + f, size() - f));
std::destroy(end() - n, end());