diff options
author | Lars Knoll <lars.knoll@qt.io> | 2019-11-16 23:25:26 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-07-06 21:29:58 +0200 |
commit | 76004502baa118016c8e0f32895af7a822f1ba37 (patch) | |
tree | 3fb524e333cb2edf6e983c4898c76f9eebb04eb4 /src/corelib/tools/qarraydata.cpp | |
parent | 2e51686746c45055e5bb74f58e0c159bfb6a8c13 (diff) |
Get rid of shared null for QByteArray, QString and QVector
As a side effect, data() can now return a nullptr. This
has the potential to cause crashes in existig code. To work
around this, return an empty string from QString::data()
and QByteArray::data() for now.
For Qt 6 (and once all our internal issues are fixed), data()
will by default return a nullptr for a null QString, but we'll
offer a #define to enable backwards compatible behavior.
Change-Id: I4f66d97ff1dce3eb99a239f1eab9106fa9b1741a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qarraydata.cpp')
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 514dd7c4de..9330a01a87 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -232,25 +232,15 @@ void *QArrayData::allocate(QArrayData **dptr, size_t objectSize, size_t alignmen return reinterpret_cast<void *>(data); } -QArrayData *QArrayData::prepareRawData(ArrayOptions options) Q_DECL_NOTHROW -{ - QArrayData *header = allocateData(sizeof(QArrayData), (options & ~DataTypeBits) | RawDataType); - if (header) - header->alloc = 0; - return header; -} - QPair<QArrayData *, void *> QArrayData::reallocateUnaligned(QArrayData *data, void *dataPointer, size_t objectSize, size_t capacity, ArrayOptions options) noexcept { - Q_ASSERT(data); - Q_ASSERT(data->isMutable()); - Q_ASSERT(!data->isShared()); + Q_ASSERT(!data || !data->isShared()); size_t headerSize = sizeof(QArrayData); size_t allocSize = calculateBlockSize(capacity, objectSize, headerSize, options); - qptrdiff offset = reinterpret_cast<char *>(dataPointer) - reinterpret_cast<char *>(data); + qptrdiff offset = dataPointer ? reinterpret_cast<char *>(dataPointer) - reinterpret_cast<char *>(data) : headerSize; options |= AllocatedDataType | MutableData; QArrayData *header = static_cast<QArrayData *>(::realloc(data, size_t(allocSize))); if (header) { |