summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.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-04 20:04:14 -0800
commitaab5c8e5486a6484feddfae0b04fd39fd244d9b9 (patch)
treeda023aae29e528259eec19ef88ea1640f4317f6f /src/corelib/text/qstring.cpp
parent302254f90f41509b3d1111551296134cd76a3db5 (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/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 6c24b738d3..35a5ba9b40 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -2261,6 +2261,7 @@ QString::QString(const QChar *unicode, qsizetype size)
d = DataPointer::fromRawData(&_empty, 0);
} else {
d = DataPointer(Data::allocate(size), size);
+ Q_CHECK_PTR(d.data());
memcpy(d.data(), unicode, size * sizeof(QChar));
d.data()[size] = '\0';
}
@@ -2279,6 +2280,7 @@ QString::QString(qsizetype size, QChar ch)
d = DataPointer::fromRawData(&_empty, 0);
} else {
d = DataPointer(Data::allocate(size), size);
+ Q_CHECK_PTR(d.data());
d.data()[size] = '\0';
char16_t *i = d.data() + size;
char16_t *b = d.data();
@@ -2300,6 +2302,7 @@ QString::QString(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';
}
}
@@ -2317,6 +2320,7 @@ QString::QString(qsizetype size, Qt::Initialization)
QString::QString(QChar ch)
{
d = DataPointer(Data::allocate(1), 1);
+ Q_CHECK_PTR(d.data());
d.data()[0] = ch.unicode();
d.data()[1] = '\0';
}
@@ -2507,6 +2511,7 @@ void QString::reallocData(qsizetype alloc, QArrayData::AllocationOption option)
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 * sizeof(QChar));
dd.data()[dd.size] = 0;
@@ -2523,6 +2528,7 @@ void QString::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;
@@ -2726,6 +2732,7 @@ QString& QString::insert(qsizetype i, const QChar *unicode, qsizetype size)
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);
}
@@ -5128,6 +5135,7 @@ QString QString::fromLatin1(QByteArrayView ba)
d = DataPointer::fromRawData(&_empty, 0);
} else {
d = DataPointer(Data::allocate(ba.size()), ba.size());
+ Q_CHECK_PTR(d.data());
d.data()[ba.size()] = '\0';
char16_t *dst = d.data();