Make QArrayData::shared_null zero terminated.
This is expected by QByteArray and QString Change-Id: Ib668b144bdc0d2c793018c8f8d794f249eaf935c Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
This commit is contained in:
parent
ca604b5b77
commit
d78fe5f8d3
@ -46,10 +46,17 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
const QArrayData QArrayData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
|
||||
const QArrayData QArrayData::shared_null[2] = {
|
||||
{ Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, sizeof(QArrayData) }, // shared null
|
||||
/* zero initialized terminator */};
|
||||
|
||||
static const QArrayData qt_array_empty = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
|
||||
static const QArrayData qt_array_unsharable_empty = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
|
||||
static const QArrayData qt_array[3] = {
|
||||
{ Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, sizeof(QArrayData) }, // shared empty
|
||||
{ { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, sizeof(QArrayData) }, // unsharable empty
|
||||
/* zero initialized terminator */};
|
||||
|
||||
static const QArrayData &qt_array_empty = qt_array[0];
|
||||
static const QArrayData &qt_array_unsharable_empty = qt_array[1];
|
||||
|
||||
QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
|
||||
size_t capacity, AllocationOptions options)
|
||||
|
@ -115,7 +115,8 @@ struct Q_CORE_EXPORT QArrayData
|
||||
static void deallocate(QArrayData *data, size_t objectSize,
|
||||
size_t alignment);
|
||||
|
||||
static const QArrayData shared_null;
|
||||
static const QArrayData shared_null[2];
|
||||
static QArrayData *sharedNull() { return const_cast<QArrayData*>(shared_null); }
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions)
|
||||
@ -169,8 +170,7 @@ struct QTypedArrayData
|
||||
static QTypedArrayData *sharedNull()
|
||||
{
|
||||
Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));
|
||||
return static_cast<QTypedArrayData *>(
|
||||
const_cast<QArrayData *>(&QArrayData::shared_null));
|
||||
return static_cast<QTypedArrayData *>(QArrayData::sharedNull());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -50,9 +50,9 @@ struct SharedNullVerifier
|
||||
{
|
||||
SharedNullVerifier()
|
||||
{
|
||||
Q_ASSERT(QArrayData::shared_null.ref.isStatic());
|
||||
Q_ASSERT(QArrayData::shared_null.ref.isShared());
|
||||
Q_ASSERT(QArrayData::shared_null.ref.isSharable());
|
||||
Q_ASSERT(QArrayData::shared_null[0].ref.isStatic());
|
||||
Q_ASSERT(QArrayData::shared_null[0].ref.isShared());
|
||||
Q_ASSERT(QArrayData::shared_null[0].ref.isSharable());
|
||||
}
|
||||
};
|
||||
|
||||
@ -159,7 +159,7 @@ void tst_QArrayData::referenceCounting()
|
||||
|
||||
void tst_QArrayData::sharedNullEmpty()
|
||||
{
|
||||
QArrayData *null = const_cast<QArrayData *>(&QArrayData::shared_null);
|
||||
QArrayData *null = const_cast<QArrayData *>(QArrayData::shared_null);
|
||||
QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0);
|
||||
|
||||
QVERIFY(null->ref.isStatic());
|
||||
|
Loading…
Reference in New Issue
Block a user