From 6a42363febb12c73c5cfe4df55f85bc651b4b8bf 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). Pick-to: 6.2 Change-Id: Ifb97170a930e97cb8f4194282cada0faf820cc53 Reviewed-by: Fabian Kosmale --- 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 8032663045..4d25287887 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -481,7 +481,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;