From 1b8bad9dda673f1340b50c39334eb92ee8a8c306 Mon Sep 17 00:00:00 2001 From: Frank Busse Date: Wed, 16 May 2018 22:35:54 +0100 Subject: CompressionStream: fix sporadic segfaults (uninitialised avail_in) --- lib/Support/CompressionStream.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib/Support') diff --git a/lib/Support/CompressionStream.cpp b/lib/Support/CompressionStream.cpp index 2e6df113..01fe1352 100644 --- a/lib/Support/CompressionStream.cpp +++ b/lib/Support/CompressionStream.cpp @@ -40,14 +40,19 @@ compressed_fd_ostream::compressed_fd_ostream(const char *Filename, FD = -1; } // Initialize the compression library - strm.zalloc = 0; - strm.zfree = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.next_in = Z_NULL; strm.next_out = buffer; + strm.avail_in = 0; strm.avail_out = BUFSIZE; - deflateInit2(&strm, Z_BEST_COMPRESSION, Z_DEFLATED, 15 | 16, - 8 /* memory usage default, 0 smalles, 9 highest*/, - Z_DEFAULT_STRATEGY); + const auto ret = deflateInit2(&strm, Z_BEST_COMPRESSION, Z_DEFLATED, 31, + 8 /* memory usage default, 0 smallest, 9 highest*/, + Z_DEFAULT_STRATEGY); + if (ret != Z_OK) + ErrorInfo = "Deflate initialisation returned with error: " + std::to_string(ret); } void compressed_fd_ostream::writeFullCompressedData() { @@ -91,7 +96,7 @@ void compressed_fd_ostream::write_impl(const char *Ptr, size_t Size) { // Check if there is still data to compress while (strm.avail_in != 0) { // compress data - int res = deflate(&strm, Z_NO_FLUSH); (void) res; + const auto res __attribute__ ((unused)) = deflate(&strm, Z_NO_FLUSH); assert(res == Z_OK); writeFullCompressedData(); } -- cgit 1.4.1