From ede290fbd941a6d5bef4a7ed0d7da2ec5ed39964 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 9 Sep 2022 12:45:06 +0200 Subject: [PATCH] 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 Reviewed-by: Thiago Macieira (cherry picked from commit 368905bce36a503e53e1567d8453277e0a6d30fa) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qbytearray.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 16b4eef69cf..d07f92ec4d7 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -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");