dovecot-2.2: lib-compression: Fixed LZMA compression.

dovecot at dovecot.org dovecot at dovecot.org
Wed May 7 10:03:24 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/8e6d98d34dbf
changeset: 17326:8e6d98d34dbf
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 07 12:26:38 2014 +0300
description:
lib-compression: Fixed LZMA compression.
The code now looks more like the doc/examples/01_compress_easy.c distributed
with xz-utils. Most importantly this changes LZMA_OK to be allowed as a
result for lzma_code(zs, LZMA_FINISH).

diffstat:

 src/lib-compression/ostream-lzma.c |  34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)

diffs (68 lines):

diff -r 4493e070c47e -r 8e6d98d34dbf src/lib-compression/ostream-lzma.c
--- a/src/lib-compression/ostream-lzma.c	Tue May 06 15:34:00 2014 +0300
+++ b/src/lib-compression/ostream-lzma.c	Wed May 07 12:26:38 2014 +0300
@@ -83,7 +83,8 @@
 			}
 		}
 
-		switch (lzma_code(zs, LZMA_RUN)) {
+		ret = lzma_code(zs, LZMA_RUN);
+		switch (ret) {
 		case LZMA_OK:
 			break;
 		case LZMA_MEM_ERROR:
@@ -91,7 +92,8 @@
 				       "lzma.write(%s): Out of memory",
 				       o_stream_get_name(&zstream->ostream.ostream));
 		default:
-			i_unreached();
+			i_panic("lzma.write(%s) failed with unexpected code %d",
+				o_stream_get_name(&zstream->ostream.ostream), ret);
 		}
 	}
 	size -= zs->avail_in;
@@ -122,20 +124,10 @@
 
 	i_assert(zstream->outbuf_used == 0);
 	do {
-		len = sizeof(zstream->outbuf) - zs->avail_out;
-		if (len != 0) {
-			zs->next_out = zstream->outbuf;
-			zs->avail_out = sizeof(zstream->outbuf);
-
-			zstream->outbuf_used = len;
-			if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0)
-				return ret;
-			if (done)
-				break;
-		}
-
 		ret = lzma_code(zs, LZMA_FINISH);
 		switch (ret) {
+		case LZMA_OK:
+			break;
 		case LZMA_STREAM_END:
 			done = TRUE;
 			break;
@@ -144,9 +136,19 @@
 				       "lzma.write(%s): Out of memory",
 				       o_stream_get_name(&zstream->ostream.ostream));
 		default:
-			i_unreached();
+			i_panic("lzma.write(%s) flush failed with unexpected code %d",
+				o_stream_get_name(&zstream->ostream.ostream), ret);
 		}
-	} while (zs->avail_out != sizeof(zstream->outbuf));
+		if (zs->avail_out == 0 || done) {
+			len = sizeof(zstream->outbuf) - zs->avail_out;
+			zs->next_out = zstream->outbuf;
+			zs->avail_out = sizeof(zstream->outbuf);
+
+			zstream->outbuf_used = len;
+			if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0)
+				return ret;
+		}
+	} while (!done);
 
 	zstream->flushed = TRUE;
 	return 0;


More information about the dovecot-cvs mailing list