From 41287d355b9571db0fbdf5841b31595705af0102 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 11 Oct 2013 13:42:01 -0700 Subject: Add QArrayData::sharedNullData() Just to simplify a few operations, like detecting when a QChar* or char* coming from a QString or QByteArray, respectively, were null data. While you're not supposed to dereference the pointer returned by QVector::data() unless you know that the array is non-empty, that is permitted for QString and QByteArray. That is, QString().constData() must return a valid pointer to a null QChar. Change-Id: I80b4b62f203dc841e5c99c20c51d92ca576e4bfe Reviewed-by: Simon Hausmann --- src/corelib/tools/qarraydata.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/corelib/tools/qarraydata.h') diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index a2d9901677..a91dd54262 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -122,6 +122,12 @@ struct Q_CORE_EXPORT QArrayData static const QArrayData shared_null[2]; static QArrayData *sharedNull() noexcept { return const_cast(shared_null); } + static void *sharedNullData() + { + QArrayData *const null = const_cast(&shared_null[1]); + Q_ASSERT(sharedNull()->data() == null); + return null; + } }; Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions) @@ -273,6 +279,12 @@ struct QTypedArrayData Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); return allocate(/* capacity */ 0); } + + static T *sharedNullData() + { + Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); + return static_cast(QArrayData::sharedNullData()); + } }; template -- cgit v1.2.3