]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: Fixed LZMA compression.
authorTimo Sirainen <tss@iki.fi>
Wed, 7 May 2014 09:26:38 +0000 (12:26 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 7 May 2014 09:26:38 +0000 (12:26 +0300)
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).

src/lib-compression/ostream-lzma.c

index 095f7d231ccfcf7a794911cc60926761aa19fa9c..f25dd7a06578dcc2cf07436c8601fd2ef09dddca 100644 (file)
@@ -83,7 +83,8 @@ o_stream_lzma_send_chunk(struct lzma_ostream *zstream,
                        }
                }
 
-               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 @@ o_stream_lzma_send_chunk(struct lzma_ostream *zstream,
                                       "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 @@ static int o_stream_lzma_send_flush(struct lzma_ostream *zstream)
 
        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 @@ static int o_stream_lzma_send_flush(struct lzma_ostream *zstream)
                                       "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);
+               }
+               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 (zs->avail_out != sizeof(zstream->outbuf));
+       } while (!done);
 
        zstream->flushed = TRUE;
        return 0;