summaryrefslogtreecommitdiff
path: root/src/compress.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-06-03 19:00:07 -0400
committerjakob <jakob@memeware.net>2017-06-03 19:00:07 -0400
commit17b658ceadd08d693f23448c276958e2eea5970e (patch)
tree8d0f62709646de856373a0ffa4fc2513f717f770 /src/compress.c
parent6adad1bfad91274aad030cf6167c1f19fb602d62 (diff)
Fully working repacker, no bugs related to the encoded output being larger than the buffer, and filenames are properly encoded.
Diffstat (limited to 'src/compress.c')
-rw-r--r--src/compress.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/compress.c b/src/compress.c
index 71e0ae3..e61780d 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -82,9 +82,17 @@ struct stream *stream_deflate(struct stream *s, size_t len) {
strm.avail_out = len;
strm.next_out = (unsigned char *) new->_cur;
deflate(&strm, Z_FINISH);
+
+ /* This means that the compressed data is larger than the
+ decompressed, and that the buffer needs to be expanded. */
+ if (strm.avail_out == 0) {
+ new->_cur += len;
+ stream_expand(new, s->len);
+ }
} while (strm.avail_out == 0);
- new->len = len - strm.avail_out;
+ new->len -= strm.avail_out;
+ new->_cur = new->_start;
deflateEnd(&strm);
return new;