summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearray.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-11-16 12:36:12 -0800
committerThiago Macieira <thiago.macieira@intel.com>2020-12-05 18:42:04 +0000
commitf77caf4c605904f661f8520f54bfab42be0c01a5 (patch)
tree705f3863ad9eccecbc9122af671f2b67a1bb560c /src/corelib/text/qbytearray.cpp
parent07b6b25c4c123640c6ed65ce5d68cec46c6281c1 (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> (cherry picked from commit aab5c8e5486a6484feddfae0b04fd39fd244d9b9) Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r--src/corelib/text/qbytearray.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 6de923fe29..21f187012b 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -1668,6 +1668,7 @@ QByteArray::QByteArray(const char *data, qsizetype size)
d = DataPointer::fromRawData(&_empty, 0);
} else {
d = DataPointer(Data::allocate(size), size);
+ Q_CHECK_PTR(d.data());
memcpy(d.data(), data, size);
d.data()[size] = '\0';
}
@@ -1686,6 +1687,7 @@ QByteArray::QByteArray(qsizetype size, char ch)
d = DataPointer::fromRawData(&_empty, 0);
} else {
d = DataPointer(Data::allocate(size), size);
+ Q_CHECK_PTR(d.data());
memset(d.data(), ch, size);
d.data()[size] = '\0';
}
@@ -1703,6 +1705,7 @@ QByteArray::QByteArray(qsizetype size, Qt::Initialization)
d = DataPointer::fromRawData(&_empty, 0);
} else {
d = DataPointer(Data::allocate(size), size);
+ Q_CHECK_PTR(d.data());
d.data()[size] = '\0';
}
}
@@ -1766,6 +1769,7 @@ void QByteArray::reallocData(qsizetype alloc, QArrayData::AllocationOption optio
if (d->needsDetach() || cannotUseReallocate) {
DataPointer dd(Data::allocate(alloc, option), qMin(alloc, d.size));
+ Q_CHECK_PTR(dd.data());
if (dd.size > 0)
::memcpy(dd.data(), d.data(), dd.size);
dd.data()[dd.size] = 0;
@@ -1782,6 +1786,7 @@ void QByteArray::reallocGrowData(qsizetype n)
if (d->needsDetach()) {
DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::GrowsAtEnd));
+ Q_CHECK_PTR(dd.data());
dd->copyAppend(d.data(), d.data() + d.size);
dd.data()[dd.size] = 0;
d = dd;
@@ -2000,6 +2005,7 @@ QByteArray &QByteArray::insert(qsizetype i, QByteArrayView data)
DataPointer detached{}; // construction is free
if (d->needsDetach() || i + size - d->size > d.freeSpaceAtEnd()) {
detached = DataPointer::allocateGrow(d, i + size - d->size, Data::GrowsAtEnd);
+ Q_CHECK_PTR(detached.data());
detached->copyAppend(d.constBegin(), d.constEnd());
d.swap(detached);
}
@@ -2081,6 +2087,7 @@ QByteArray &QByteArray::insert(qsizetype i, qsizetype count, char ch)
// handle this specially, as QArrayDataOps::insert() doesn't handle out of bounds positions
if (d->needsDetach() || i + count - d->size > d.freeSpaceAtEnd()) {
DataPointer detached(DataPointer::allocateGrow(d, i + count - d->size, Data::GrowsAtEnd));
+ Q_CHECK_PTR(detached.data());
detached->copyAppend(d.constBegin(), d.constEnd());
d.swap(detached);
}