summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2016-11-22 14:52:18 -0800
committerThiago Macieira <thiago.macieira@intel.com>2016-12-17 02:23:20 +0000
commitbfed4aadaf89c59a3b7a0894836cc0469ac75c3a (patch)
tree6ecdf9483e1e9f39c538dcd68a94055f0e3e3639 /src
parent02150649f95b8f46f826e6e002be3fa0b6d009bc (diff)
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 (cherry-picked from commit b0c321a8db7b75d740d968c6a583473600faf990) Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qvarlengtharray.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 8371352061..d54121f452 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -70,7 +70,8 @@ public:
QVarLengthArray(std::initializer_list<T> args)
: a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array))
{
- append(args.begin(), args.size());
+ if (args.size())
+ append(args.begin(), args.size());
}
#endif