qCompress: use qToBigEndian() to write the length prefix

Better explains what the code is doing, esp. now that qUncompress() is
using qFromBigEndian() for the inverse operation.

Task-number: QTBUG-104972
Change-Id: Ic885fd31bd80dc3939c7e4ef0c0e53b9e6b185b3
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 368905bce36a503e53e1567d8453277e0a6d30fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-09-09 12:45:06 +02:00
parent 551898e63d
commit ede290fbd9

View File

@ -550,10 +550,7 @@ QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel)
switch (res) {
case Z_OK:
bazip.resize(len + 4);
bazip[0] = (nbytes & 0xff000000) >> 24;
bazip[1] = (nbytes & 0x00ff0000) >> 16;
bazip[2] = (nbytes & 0x0000ff00) >> 8;
bazip[3] = (nbytes & 0x000000ff);
qToBigEndian(quint32(nbytes), bazip.data()); // 4 octets, historically
break;
case Z_MEM_ERROR:
qWarning("qCompress: Z_MEM_ERROR: Not enough memory");