From 98d9cfabc19984d75951f7ee66037331da63c0b8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Sep 2022 11:12:54 +0200 Subject: [PATCH] qCompress: return null, not empty, for OOM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While this is a behavior change, we never documented that we'd return an empty instead of a null QByteArray in this situation. Indeed, returning bazip, with its fully-preserved capacity, is an expensive way of signalling an error condition. Conclude that this is not what the original author wanted and return a default-constructed byte array instead, leaving bazip and its excess capacity to be destroyed before the return from the function. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-104972 Task-number: QTBUG-106542 Change-Id: I2ee1fc6fdbb9da28f1987b16915516b51bb348c3 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/text/qbytearray.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 6ae0237d55..fb55c630bf 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -606,9 +606,8 @@ QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel) qToBigEndian(CompressSizeHint_t(nbytes), bazip.data()); break; case Z_MEM_ERROR: - qWarning("qCompress: Z_MEM_ERROR: Not enough memory"); - bazip.resize(0); - break; + return tooMuchData(ZLibOp::Compression); + case Z_BUF_ERROR: len *= 2; break;