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).

Change-Id: Ifb97170a930e97cb8f4194282cada0faf820cc53
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 6a42363febb12c73c5cfe4df55f85bc651b4b8bf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2021-12-10 10:54:26 +01:00 committed by Qt Cherry-pick Bot
parent b05c9898cc
commit 4e669763bd

View File

@ -466,7 +466,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;