qCompress: return null, not empty, for OOM

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 <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2022-09-21 11:12:54 +02:00
parent 305d164508
commit 98d9cfabc1

View File

@ -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;