summaryrefslogtreecommitdiff
path: root/test/gh1235.c
diff options
context:
space:
mode:
authoralk3pInjection <webmaster@raspii.tech>2023-04-20 00:08:54 +0800
committeralk3pInjection <webmaster@raspii.tech>2023-04-20 00:08:54 +0800
commit004b98220a30de0d1956a8149d8bc6ec356667da (patch)
tree1eaee2603984d7ab4524be68b57ce0a2b2b72118 /test/gh1235.c
parent2ca0d0b38b60e8d6d49a8959bf674a79e7d16f41 (diff)
parenta583e215afa2356e23b418efa871a1cc4348702a (diff)
Merge tag '2.0.7' into tachibanatachibana-mr1tachibana
Change-Id: I7b03d60d67d184c21ff7437a35062077666951e9
Diffstat (limited to 'test/gh1235.c')
-rw-r--r--test/gh1235.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/gh1235.c b/test/gh1235.c
new file mode 100644
index 0000000..472282d
--- /dev/null
+++ b/test/gh1235.c
@@ -0,0 +1,39 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include "zutil.h"
+
+int main(void) {
+ unsigned char plain[32];
+ unsigned char compressed[130];
+ PREFIX3(stream) strm;
+ int bound;
+ z_size_t bytes;
+
+ for (int i = 0; i <= 32; i++) {
+ memset(plain, 6, i);
+ memset(&strm, 0, sizeof(strm));
+ PREFIX(deflateInit2)(&strm, 0, 8, 31, 1, Z_DEFAULT_STRATEGY);
+ bound = PREFIX(deflateBound)(&strm, i);
+ strm.next_in = plain;
+ strm.next_out = compressed;
+ strm.avail_in = i;
+ strm.avail_out = sizeof(compressed);
+ if (PREFIX(deflate)(&strm, Z_FINISH) != Z_STREAM_END) return -1;
+ if (strm.avail_in != 0) return -1;
+ printf("bytes = %2i, deflateBound = %2i, total_out = %2zi\n", i, bound, strm.total_out);
+ if (bound < strm.total_out) return -1;
+ if (PREFIX(deflateEnd)(&strm) != Z_OK) return -1;
+ }
+ for (int i = 0; i <= 32; i++) {
+ bytes = sizeof(compressed);
+ for (int j = 0; j < i; j++) {
+ plain[j] = j;
+ }
+ bound = PREFIX(compressBound)(i);
+ if (PREFIX(compress2)(compressed, &bytes, plain, i, 1) != Z_OK) return -1;
+ printf("bytes = %2i, compressBound = %2i, total_out = %2zi\n", i, bound, (size_t)bytes);
+ if (bytes > bound) return -1;
+ }
+ return 0;
+}