From 1da924462940ce3d22ec2dc24eafb7c644496161 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 7 Sep 2022 16:32:11 +0200 Subject: [PATCH] qUncompress: mark invalidCompressedData() Q_DECL_COLD_FUNCTION ... and in turn remove the manual Q_UNLIKELY() leading to its callers. Paths to Q_DECL_COLD_FUNCTIONs are implicitly [[unlikely]]. This is in preparation of changes where the extra Q_UNLIKELY markup gets in the way. Task-number: QTBUG-104972 Change-Id: I2cba5103854bf356ed841e1957a5ef143f8d3823 Reviewed-by: Thiago Macieira (cherry picked from commit 936d33849c31c020edfa9fdf04aec29d14cb133f) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qbytearray.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index b517f62e56e..0559ff8fd5d 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -602,6 +602,7 @@ QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel) */ #ifndef QT_NO_COMPRESS +Q_DECL_COLD_FUNCTION static QByteArray invalidCompressedData() { qWarning("qUncompress: Input data is corrupted"); @@ -632,13 +633,13 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) (data[2] << 8) | (data[3] )); size_t len = qMax(expectedSize, 1ul); constexpr size_t maxPossibleSize = MaxAllocSize - sizeof(QByteArray::Data); - if (Q_UNLIKELY(len >= maxPossibleSize)) { + if (len >= maxPossibleSize) { // QByteArray does not support that huge size anyway. return invalidCompressedData(); } QByteArray::DataPointer d(QByteArray::Data::allocate(len)); - if (Q_UNLIKELY(d.data() == nullptr)) + if (d.data() == nullptr) // allocation failed return invalidCompressedData(); forever { @@ -663,13 +664,13 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) static_assert(maxPossibleSize <= (std::numeric_limits::max)() / 2, "oops, next line may overflow"); len *= 2; - if (Q_UNLIKELY(len >= maxPossibleSize)) { + if (len >= maxPossibleSize) { // QByteArray does not support that huge size anyway. return invalidCompressedData(); } else { // grow the block d->reallocate(d->allocatedCapacity()*2, QArrayData::Grow); - if (Q_UNLIKELY(d.data() == nullptr)) + if (d.data() == nullptr) // reallocation failed return invalidCompressedData(); } continue;