From 72fddb0935a47d94c0fec11e9ee10701211b422e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 4 Mar 2025 11:14:04 +0100 Subject: [PATCH] QZip: fix Coverity warning about reading uninit'ed fields from z_stream Coverity complains that inflateInit2() will read stream.opaque, which wasn't initialized by us. At least in the copy of zlib that is contained in Qt, this is false. But xxflate() in qbytearray.cpp value-initializes its z_stream (and therefore doesn't manually need to set .zalloc and .zfree), so do that here, too. Amends the start of the public history. Pick-to: 6.8 6.5 Coverity-Id: 310213 Change-Id: I487072a0d2375a932f3ffb9a1f252fec9e2f2d0d Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Thiago Macieira (cherry picked from commit a817ba8e9c42dfffd31eb26ac522488c2a4ec61e) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qzip.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/corelib/io/qzip.cpp b/src/corelib/io/qzip.cpp index 1e3d5f5859e..12224ff4d33 100644 --- a/src/corelib/io/qzip.cpp +++ b/src/corelib/io/qzip.cpp @@ -91,7 +91,7 @@ static void writeMSDosDate(uchar *dest, const QDateTime& dt) static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen) { - z_stream stream; + z_stream stream = {}; int err; stream.next_in = const_cast(source); @@ -104,9 +104,6 @@ static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourc if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - stream.zalloc = (alloc_func)nullptr; - stream.zfree = (free_func)nullptr; - err = inflateInit2(&stream, -MAX_WBITS); if (err != Z_OK) return err;