{"thread":{"id":"11586","subject":"[PATCH 1/6] Better error handling in compress_all()","startedAt":"2008-01-11T18:53:02Z","lastAt":"2008-01-11T18:53:02Z","messageCount":1,"participants":["Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"65044","messageId":"e5bfff550801111053v55fd2fc3ice97e6ae10c8f942@mail.gmail.com","threadId":"11586","inReplyTo":null,"subject":"[PATCH 1/6] Better error handling in compress_all()","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-11T18:53:02Z","receivedAt":"2008-01-11T18:53:02Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"Also let the caller to xmalloc() the buffer\nint compress_start()\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n\nThis patch belong to the previous compression series,\nnot the decompression one that I'm publishing right now.\n\nAnyhow next patches depends on this, so that's the reason\nwhy is the first.\n\n\n compress.c |   19 +++++++++----------\n 1 files changed, 9 insertions(+), 10 deletions(-)\n\ndiff --git a/compress.c b/compress.c\nindex be771a9..a8f46d5 100644\n--- a/compress.c\n+++ b/compress.c\n@@ -12,7 +12,7 @@ int compress_start(z_stream *stream,\n                    unsigned char *in, unsigned long in_size,\n                    unsigned char *out, unsigned long out_size)\n {\n-\tstream->next_out = (out ? out : xmalloc(out_size));\n+\tstream->next_out = out;\n \tstream->avail_out = out_size;\n \tstream->next_in = in;\n \tstream->avail_in = in_size;\n@@ -36,19 +36,18 @@ unsigned long compress_free(z_stream\n \treturn stream->total_out;\n }\n\n-unsigned long compress_all(int level, unsigned char *data,\n-                           unsigned long size, unsigned char **out)\n+unsigned long compress_all(int level, unsigned char *in,\n+                           unsigned long in_size, unsigned char **out)\n {\n-\tint bound, result;\n+\tunsigned long out_size;\n \tz_stream stream;\n\n-\tbound = compress_alloc(&stream, level, size);\n-\tcompress_start(&stream, data, size, NULL, bound);\n+\tout_size = compress_alloc(&stream, level, in_size);\n+\t*out = xmalloc(out_size);\n\n-\t*out = stream.next_out;\n-\tresult = compress_next(&stream, Z_FINISH);\n-\n-\tif (result != Z_STREAM_END) {\n+\tif (   compress_start(&stream, in, in_size, *out, out_size) != Z_OK\n+\t    || compress_next(&stream, Z_FINISH) != Z_STREAM_END)\n+\t{\n \t\tcompress_free(&stream);\n \t\tfree(*out);\n \t\t*out = NULL;\n-- \n1.5.4.rc2.90.gf158-dirty\n"}]}