diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2020-11-16 12:36:12 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-12-04 20:04:14 -0800 |
commit | aab5c8e5486a6484feddfae0b04fd39fd244d9b9 (patch) | |
tree | da023aae29e528259eec19ef88ea1640f4317f6f /src/corelib/tools | |
parent | 302254f90f41509b3d1111551296134cd76a3db5 (diff) |
QString/QByteArray: add missing Q_CHECK_PTR
So these two classes throw when trying to allocate silly sizes or in OOM
conditions.
We probably want to move these Q_CHECK_POINTER into QTypedArrayData but
I didn't want to do that in this commit.
Task-number: QTBUG-88256
Task-number: QTBUG-88253
Change-Id: Ifc61bb80b9bf48a386abfffd1648176111770174
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 2 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 5feb1ac8f6..8ca315024d 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -235,6 +235,9 @@ QArrayData::reallocateUnaligned(QArrayData *data, void *dataPointer, const qsizetype headerSize = sizeof(QArrayData); qsizetype allocSize = calculateBlockSize(capacity, objectSize, headerSize, option); + if (Q_UNLIKELY(allocSize < 0)) + return qMakePair<QArrayData *, void *>(nullptr, nullptr); + const qptrdiff offset = dataPointer ? reinterpret_cast<char *>(dataPointer) - reinterpret_cast<char *>(data) : headerSize; diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index cf054a089f..0c7703c588 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -286,6 +286,7 @@ public: void reallocate(qsizetype alloc, QArrayData::AllocationOption option) { auto pair = Data::reallocateUnaligned(this->d, this->ptr, alloc, option); + Q_CHECK_PTR(pair.second); Q_ASSERT(pair.first != nullptr); this->d = pair.first; this->ptr = pair.second; @@ -849,6 +850,7 @@ public: void reallocate(qsizetype alloc, QArrayData::AllocationOption option) { auto pair = Data::reallocateUnaligned(this->d, this->ptr, alloc, option); + Q_CHECK_PTR(pair.second); Q_ASSERT(pair.first != nullptr); this->d = pair.first; this->ptr = pair.second; |