QVarLengthArray: widen append(p, n)'s contract

It's a bit weird that the (counted-)range-append() allows n < 0, but
requires p != nullptr even when n == 0.

Fix by allowing p == nullptr iff n == 0.

[ChangeLog][QtCore][QVarLengthArray] The counted-range-append()
function (append(ptr, n)) now accepts ptr == nullptr, provided n == 0,
too (was: triggered assertion).

Pick-to: 6.2
Change-Id: Ifb97170a930e97cb8f4194282cada0faf820cc53
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Marc Mutz 2021-12-10 10:54:26 +01:00
parent bc4570ed24
commit 6a42363feb

View File

@ -481,7 +481,7 @@ Q_INLINE_TEMPLATE bool QVarLengthArray<T, Prealloc>::contains(const AT &t) const
template <class T, qsizetype Prealloc>
Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::append(const T *abuf, qsizetype increment)
{
Q_ASSERT(abuf);
Q_ASSERT(abuf || increment == 0);
if (increment <= 0)
return;