From 4e669763bdb61c873b747012a648a71d62a31cd2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 10 Dec 2021 10:54:26 +0100 Subject: [PATCH] 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 (cherry picked from commit 6a42363febb12c73c5cfe4df55f85bc651b4b8bf) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qvarlengtharray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 168f11e06ab..e37ad64fcd8 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -466,7 +466,7 @@ Q_INLINE_TEMPLATE bool QVarLengthArray::contains(const AT &t) const template Q_OUTOFLINE_TEMPLATE void QVarLengthArray::append(const T *abuf, qsizetype increment) { - Q_ASSERT(abuf); + Q_ASSERT(abuf || increment == 0); if (increment <= 0) return;