Provide memory allocator functions to zlib so that it is able to allocate memory and then deflate later. Also, some minor error-handling things.
-- v2: opcservices: Check for memory allocation failure before deflating.
From: Danyil Blyschak dblyschak@codeweavers.com
--- dlls/opcservices/compress.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/dlls/opcservices/compress.c b/dlls/opcservices/compress.c index 37a90716a74..186469a782c 100644 --- a/dlls/opcservices/compress.c +++ b/dlls/opcservices/compress.c @@ -184,6 +184,16 @@ void compress_finalize_archive(struct zip_archive *archive) free(archive); }
+static void *zalloc(void *opaque, unsigned int items, unsigned int size) +{ + return malloc(items * size); +} + +static void zfree(void *opaque, void *ptr) +{ + free(ptr); +} + static void compress_write_content(struct zip_archive *archive, IStream *content, OPC_COMPRESSION_OPTIONS options, struct data_descriptor *data_desc) { @@ -220,6 +230,8 @@ static void compress_write_content(struct zip_archive *archive, IStream *content }
memset(&z_str, 0, sizeof(z_str)); + z_str.zalloc = zalloc; + z_str.zfree = zfree; deflateInit2(&z_str, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
do
From: Danyil Blyschak dblyschak@codeweavers.com
Zlib documents that negative return values for this function are errors and positive ones are special but normal events. --- dlls/opcservices/compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/opcservices/compress.c b/dlls/opcservices/compress.c index 186469a782c..841c674c26c 100644 --- a/dlls/opcservices/compress.c +++ b/dlls/opcservices/compress.c @@ -257,7 +257,7 @@ static void compress_write_content(struct zip_archive *archive, IStream *content z_str.avail_out = sizeof(archive->output_buffer); z_str.next_out = archive->output_buffer;
- if ((ret = deflate(&z_str, flush))) + if ((ret = deflate(&z_str, flush)) < 0) WARN("Failed to deflate, ret %d.\n", ret); have = sizeof(archive->output_buffer) - z_str.avail_out; compress_write(archive, archive->output_buffer, have);
From: Danyil Blyschak dblyschak@codeweavers.com
--- dlls/opcservices/compress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dlls/opcservices/compress.c b/dlls/opcservices/compress.c index 841c674c26c..78b38f8437a 100644 --- a/dlls/opcservices/compress.c +++ b/dlls/opcservices/compress.c @@ -202,6 +202,7 @@ static void compress_write_content(struct zip_archive *archive, IStream *content LARGE_INTEGER move; ULONG num_read; HRESULT hr; + int init_ret;
data_desc->crc32 = RtlComputeCrc32(0, NULL, 0); move.QuadPart = 0; @@ -232,7 +233,8 @@ static void compress_write_content(struct zip_archive *archive, IStream *content memset(&z_str, 0, sizeof(z_str)); z_str.zalloc = zalloc; z_str.zfree = zfree; - deflateInit2(&z_str, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); + if ((init_ret = deflateInit2(&z_str, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) != Z_OK) + WARN("Failed to allocate memory in deflateInit2, ret %d.\n", init_ret);
do {
On Thu Jun 13 18:57:22 2024 +0000, Nikolay Sivov wrote:
Please add a space after "if". I see no issues otherwise.
Alright, I just pushed a commit with an added space.