summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvarlengtharray.h
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-09 03:11:34 +0000
commitb0c321a8db7b75d740d968c6a583473600faf990 (patch)
tree1851f55318a407d13dac000aec9fd5cba36356ea /src/corelib/tools/qvarlengtharray.h
parent2c9dc93696f32b798b872f931c102329d0ba7155 (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 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qvarlengtharray.h')
-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 c3ac104399..1530299303 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -76,7 +76,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