From b0c321a8db7b75d740d968c6a583473600faf990 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 22 Nov 2016 14:52:18 -0800 Subject: Don't crash on QVLA construction from an empty std::initializer_list The C++ standard says in [support.initlist.access]/1: constexpr const E* begin() const noexcept; Returns: A pointer to the beginning of the array. If size() == 0 the values of begin() and end() are unspecified but they shall be identical. So we can't assume it's non-null. I didn't want to remove the Q_ASSERT, so passing a non-null pointer to append() remains required. This patch simply won't call append() if the initializer list is empty. This was already tested, but the failure is with a compiler that is not part of the Qt CI. Task-number: QTBUG-57277 Change-Id: Iaeecaffe26af4535b416fffd1489806872b412ee Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qvarlengtharray.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools/qvarlengtharray.h') diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index c3ac104399..1530299303 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -76,7 +76,8 @@ public: QVarLengthArray(std::initializer_list args) : a(Prealloc), s(0), ptr(reinterpret_cast(array)) { - append(args.begin(), args.size()); + if (args.size()) + append(args.begin(), args.size()); } #endif -- cgit v1.2.3