11cb0ef41Sopenharmony_ciFrom 409594639f15d825202971db7a275023e05772ff Mon Sep 17 00:00:00 2001
21cb0ef41Sopenharmony_ciFrom: Adenilson Cavalcanti <adenilson.cavalcanti@arm.com>
31cb0ef41Sopenharmony_ciDate: Tue, 28 Apr 2020 10:48:01 -0700
41cb0ef41Sopenharmony_ciSubject: [PATCH] Local Changes:   - make C tests build as C++ code so we can
51cb0ef41Sopenharmony_ci use gtest.   - use gtest EXPECT_TRUE instead of C assert.   - replace C
61cb0ef41Sopenharmony_ci streams for C++ (portability issues).
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci---
91cb0ef41Sopenharmony_ci test/infcover.c | 167 ++++++++++++++++++++++++++----------------------
101cb0ef41Sopenharmony_ci 1 file changed, 90 insertions(+), 77 deletions(-)
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cidiff --git a/test/infcover.c b/test/infcover.c
131cb0ef41Sopenharmony_ciindex 2be0164..a8c51c7 100644
141cb0ef41Sopenharmony_ci--- a/test/infcover.c
151cb0ef41Sopenharmony_ci+++ b/test/infcover.c
161cb0ef41Sopenharmony_ci@@ -4,11 +4,12 @@
171cb0ef41Sopenharmony_ci  */
181cb0ef41Sopenharmony_ci 
191cb0ef41Sopenharmony_ci /* to use, do: ./configure --cover && make cover */
201cb0ef41Sopenharmony_ci-
211cb0ef41Sopenharmony_ci+// clang-format off
221cb0ef41Sopenharmony_ci+#include "infcover.h"
231cb0ef41Sopenharmony_ci #include <stdio.h>
241cb0ef41Sopenharmony_ci #include <stdlib.h>
251cb0ef41Sopenharmony_ci #include <string.h>
261cb0ef41Sopenharmony_ci-#include <assert.h>
271cb0ef41Sopenharmony_ci+
281cb0ef41Sopenharmony_ci #include "zlib.h"
291cb0ef41Sopenharmony_ci 
301cb0ef41Sopenharmony_ci /* get definition of internal structure so we can mess with it (see pull()),
311cb0ef41Sopenharmony_ci@@ -17,8 +18,22 @@
321cb0ef41Sopenharmony_ci #include "inftrees.h"
331cb0ef41Sopenharmony_ci #include "inflate.h"
341cb0ef41Sopenharmony_ci 
351cb0ef41Sopenharmony_ci+/* XXX: use C++ streams instead of printf/fputs/etc due to portability
361cb0ef41Sopenharmony_ci+ * as type sizes can vary between platforms.
371cb0ef41Sopenharmony_ci+ */
381cb0ef41Sopenharmony_ci+#include <iostream>
391cb0ef41Sopenharmony_ci #define local static
401cb0ef41Sopenharmony_ci 
411cb0ef41Sopenharmony_ci+/* XXX: hacking C assert and plugging into GTest. */
421cb0ef41Sopenharmony_ci+#include "gtest.h"
431cb0ef41Sopenharmony_ci+#if defined(assert)
441cb0ef41Sopenharmony_ci+#undef assert
451cb0ef41Sopenharmony_ci+#define assert EXPECT_TRUE
461cb0ef41Sopenharmony_ci+#endif
471cb0ef41Sopenharmony_ci+
481cb0ef41Sopenharmony_ci+/* XXX: handle what is a reserved word in C++. */
491cb0ef41Sopenharmony_ci+#define try try_f
501cb0ef41Sopenharmony_ci+
511cb0ef41Sopenharmony_ci /* -- memory tracking routines -- */
521cb0ef41Sopenharmony_ci 
531cb0ef41Sopenharmony_ci /*
541cb0ef41Sopenharmony_ci@@ -72,7 +87,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
551cb0ef41Sopenharmony_ci {
561cb0ef41Sopenharmony_ci     void *ptr;
571cb0ef41Sopenharmony_ci     struct mem_item *item;
581cb0ef41Sopenharmony_ci-    struct mem_zone *zone = mem;
591cb0ef41Sopenharmony_ci+    struct mem_zone *zone = static_cast<struct mem_zone *>(mem);
601cb0ef41Sopenharmony_ci     size_t len = count * (size_t)size;
611cb0ef41Sopenharmony_ci 
621cb0ef41Sopenharmony_ci     /* induced allocation failure */
631cb0ef41Sopenharmony_ci@@ -87,7 +102,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
641cb0ef41Sopenharmony_ci     memset(ptr, 0xa5, len);
651cb0ef41Sopenharmony_ci 
661cb0ef41Sopenharmony_ci     /* create a new item for the list */
671cb0ef41Sopenharmony_ci-    item = malloc(sizeof(struct mem_item));
681cb0ef41Sopenharmony_ci+    item = static_cast<struct mem_item *>(malloc(sizeof(struct mem_item)));
691cb0ef41Sopenharmony_ci     if (item == NULL) {
701cb0ef41Sopenharmony_ci         free(ptr);
711cb0ef41Sopenharmony_ci         return NULL;
721cb0ef41Sopenharmony_ci@@ -112,7 +127,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
731cb0ef41Sopenharmony_ci local void mem_free(void *mem, void *ptr)
741cb0ef41Sopenharmony_ci {
751cb0ef41Sopenharmony_ci     struct mem_item *item, *next;
761cb0ef41Sopenharmony_ci-    struct mem_zone *zone = mem;
771cb0ef41Sopenharmony_ci+    struct mem_zone *zone = static_cast<struct mem_zone *>(mem);
781cb0ef41Sopenharmony_ci 
791cb0ef41Sopenharmony_ci     /* if no zone, just do a free */
801cb0ef41Sopenharmony_ci     if (zone == NULL) {
811cb0ef41Sopenharmony_ci@@ -159,7 +174,7 @@ local void mem_setup(z_stream *strm)
821cb0ef41Sopenharmony_ci {
831cb0ef41Sopenharmony_ci     struct mem_zone *zone;
841cb0ef41Sopenharmony_ci 
851cb0ef41Sopenharmony_ci-    zone = malloc(sizeof(struct mem_zone));
861cb0ef41Sopenharmony_ci+    zone = static_cast<struct mem_zone *>(malloc(sizeof(struct mem_zone)));
871cb0ef41Sopenharmony_ci     assert(zone != NULL);
881cb0ef41Sopenharmony_ci     zone->first = NULL;
891cb0ef41Sopenharmony_ci     zone->total = 0;
901cb0ef41Sopenharmony_ci@@ -175,33 +190,33 @@ local void mem_setup(z_stream *strm)
911cb0ef41Sopenharmony_ci /* set a limit on the total memory allocation, or 0 to remove the limit */
921cb0ef41Sopenharmony_ci local void mem_limit(z_stream *strm, size_t limit)
931cb0ef41Sopenharmony_ci {
941cb0ef41Sopenharmony_ci-    struct mem_zone *zone = strm->opaque;
951cb0ef41Sopenharmony_ci+    struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
961cb0ef41Sopenharmony_ci 
971cb0ef41Sopenharmony_ci     zone->limit = limit;
981cb0ef41Sopenharmony_ci }
991cb0ef41Sopenharmony_ci 
1001cb0ef41Sopenharmony_ci /* show the current total requested allocations in bytes */
1011cb0ef41Sopenharmony_ci-local void mem_used(z_stream *strm, char *prefix)
1021cb0ef41Sopenharmony_ci+local void mem_used(z_stream *strm, const char *prefix)
1031cb0ef41Sopenharmony_ci {
1041cb0ef41Sopenharmony_ci-    struct mem_zone *zone = strm->opaque;
1051cb0ef41Sopenharmony_ci+    struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
1061cb0ef41Sopenharmony_ci 
1071cb0ef41Sopenharmony_ci-    fprintf(stderr, "%s: %lu allocated\n", prefix, zone->total);
1081cb0ef41Sopenharmony_ci+    std::cout << prefix << ": " << zone->total << " allocated" << std::endl;
1091cb0ef41Sopenharmony_ci }
1101cb0ef41Sopenharmony_ci 
1111cb0ef41Sopenharmony_ci /* show the high water allocation in bytes */
1121cb0ef41Sopenharmony_ci-local void mem_high(z_stream *strm, char *prefix)
1131cb0ef41Sopenharmony_ci+local void mem_high(z_stream *strm, const char *prefix)
1141cb0ef41Sopenharmony_ci {
1151cb0ef41Sopenharmony_ci-    struct mem_zone *zone = strm->opaque;
1161cb0ef41Sopenharmony_ci+    struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
1171cb0ef41Sopenharmony_ci 
1181cb0ef41Sopenharmony_ci-    fprintf(stderr, "%s: %lu high water mark\n", prefix, zone->highwater);
1191cb0ef41Sopenharmony_ci+    std::cout << prefix << ": " << zone->highwater << " high water mark" << std::endl;
1201cb0ef41Sopenharmony_ci }
1211cb0ef41Sopenharmony_ci 
1221cb0ef41Sopenharmony_ci /* release the memory allocation zone -- if there are any surprises, notify */
1231cb0ef41Sopenharmony_ci-local void mem_done(z_stream *strm, char *prefix)
1241cb0ef41Sopenharmony_ci+local void mem_done(z_stream *strm, const char *prefix)
1251cb0ef41Sopenharmony_ci {
1261cb0ef41Sopenharmony_ci     int count = 0;
1271cb0ef41Sopenharmony_ci     struct mem_item *item, *next;
1281cb0ef41Sopenharmony_ci-    struct mem_zone *zone = strm->opaque;
1291cb0ef41Sopenharmony_ci+    struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
1301cb0ef41Sopenharmony_ci 
1311cb0ef41Sopenharmony_ci     /* show high water mark */
1321cb0ef41Sopenharmony_ci     mem_high(strm, prefix);
1331cb0ef41Sopenharmony_ci@@ -218,13 +233,20 @@ local void mem_done(z_stream *strm, char *prefix)
1341cb0ef41Sopenharmony_ci 
1351cb0ef41Sopenharmony_ci     /* issue alerts about anything unexpected */
1361cb0ef41Sopenharmony_ci     if (count || zone->total)
1371cb0ef41Sopenharmony_ci-        fprintf(stderr, "** %s: %lu bytes in %d blocks not freed\n",
1381cb0ef41Sopenharmony_ci-                prefix, zone->total, count);
1391cb0ef41Sopenharmony_ci+        std::cout << "** " << prefix << ": "
1401cb0ef41Sopenharmony_ci+                  << zone->total << " bytes in "
1411cb0ef41Sopenharmony_ci+                  << count << " blocks not freed"
1421cb0ef41Sopenharmony_ci+                  << std::endl;
1431cb0ef41Sopenharmony_ci+
1441cb0ef41Sopenharmony_ci     if (zone->notlifo)
1451cb0ef41Sopenharmony_ci-        fprintf(stderr, "** %s: %d frees not LIFO\n", prefix, zone->notlifo);
1461cb0ef41Sopenharmony_ci+        std::cout << "** " << prefix << ": "
1471cb0ef41Sopenharmony_ci+                  << zone->notlifo << " frees not LIFO"
1481cb0ef41Sopenharmony_ci+                  << std::endl;
1491cb0ef41Sopenharmony_ci+
1501cb0ef41Sopenharmony_ci     if (zone->rogue)
1511cb0ef41Sopenharmony_ci-        fprintf(stderr, "** %s: %d frees not recognized\n",
1521cb0ef41Sopenharmony_ci-                prefix, zone->rogue);
1531cb0ef41Sopenharmony_ci+        std::cout << "** " << prefix << ": "
1541cb0ef41Sopenharmony_ci+                  << zone->rogue << " frees not recognized"
1551cb0ef41Sopenharmony_ci+                  << std::endl;
1561cb0ef41Sopenharmony_ci 
1571cb0ef41Sopenharmony_ci     /* free the zone and delete from the stream */
1581cb0ef41Sopenharmony_ci     free(zone);
1591cb0ef41Sopenharmony_ci@@ -247,7 +269,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
1601cb0ef41Sopenharmony_ci     unsigned char *in, *re;
1611cb0ef41Sopenharmony_ci     unsigned next, val;
1621cb0ef41Sopenharmony_ci 
1631cb0ef41Sopenharmony_ci-    in = malloc((strlen(hex) + 1) >> 1);
1641cb0ef41Sopenharmony_ci+    in = static_cast<unsigned char *>(malloc((strlen(hex) + 1) >> 1));
1651cb0ef41Sopenharmony_ci     if (in == NULL)
1661cb0ef41Sopenharmony_ci         return NULL;
1671cb0ef41Sopenharmony_ci     next = 0;
1681cb0ef41Sopenharmony_ci@@ -268,7 +290,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
1691cb0ef41Sopenharmony_ci     } while (*hex++);       /* go through the loop with the terminating null */
1701cb0ef41Sopenharmony_ci     if (len != NULL)
1711cb0ef41Sopenharmony_ci         *len = next;
1721cb0ef41Sopenharmony_ci-    re = realloc(in, next);
1731cb0ef41Sopenharmony_ci+    re = static_cast<unsigned char *>(realloc(in, next));
1741cb0ef41Sopenharmony_ci     return re == NULL ? in : re;
1751cb0ef41Sopenharmony_ci }
1761cb0ef41Sopenharmony_ci 
1771cb0ef41Sopenharmony_ci@@ -281,7 +303,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
1781cb0ef41Sopenharmony_ci    header information is collected with inflateGetHeader().  If a zlib stream
1791cb0ef41Sopenharmony_ci    is looking for a dictionary, then an empty dictionary is provided.
1801cb0ef41Sopenharmony_ci    inflate() is run until all of the input data is consumed. */
1811cb0ef41Sopenharmony_ci-local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
1821cb0ef41Sopenharmony_ci+local void inf(const char *hex, const char *what, unsigned step, int win, unsigned len,
1831cb0ef41Sopenharmony_ci                int err)
1841cb0ef41Sopenharmony_ci {
1851cb0ef41Sopenharmony_ci     int ret;
1861cb0ef41Sopenharmony_ci@@ -298,7 +320,7 @@ local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
1871cb0ef41Sopenharmony_ci         mem_done(&strm, what);
1881cb0ef41Sopenharmony_ci         return;
1891cb0ef41Sopenharmony_ci     }
1901cb0ef41Sopenharmony_ci-    out = malloc(len);                          assert(out != NULL);
1911cb0ef41Sopenharmony_ci+    out = static_cast<unsigned char *>(malloc(len));                          assert(out != NULL);
1921cb0ef41Sopenharmony_ci     if (win == 47) {
1931cb0ef41Sopenharmony_ci         head.extra = out;
1941cb0ef41Sopenharmony_ci         head.extra_max = len;
1951cb0ef41Sopenharmony_ci@@ -347,7 +369,7 @@ local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
1961cb0ef41Sopenharmony_ci }
1971cb0ef41Sopenharmony_ci 
1981cb0ef41Sopenharmony_ci /* cover all of the lines in inflate.c up to inflate() */
1991cb0ef41Sopenharmony_ci-local void cover_support(void)
2001cb0ef41Sopenharmony_ci+void cover_support(void)
2011cb0ef41Sopenharmony_ci {
2021cb0ef41Sopenharmony_ci     int ret;
2031cb0ef41Sopenharmony_ci     z_stream strm;
2041cb0ef41Sopenharmony_ci@@ -381,11 +403,11 @@ local void cover_support(void)
2051cb0ef41Sopenharmony_ci     strm.next_in = Z_NULL;
2061cb0ef41Sopenharmony_ci     ret = inflateInit(&strm);                   assert(ret == Z_OK);
2071cb0ef41Sopenharmony_ci     ret = inflateEnd(&strm);                    assert(ret == Z_OK);
2081cb0ef41Sopenharmony_ci-    fputs("inflate built-in memory routines\n", stderr);
2091cb0ef41Sopenharmony_ci+    std::cout << "inflate built-in memory routines" << std::endl;;
2101cb0ef41Sopenharmony_ci }
2111cb0ef41Sopenharmony_ci 
2121cb0ef41Sopenharmony_ci /* cover all inflate() header and trailer cases and code after inflate() */
2131cb0ef41Sopenharmony_ci-local void cover_wrap(void)
2141cb0ef41Sopenharmony_ci+void cover_wrap(void)
2151cb0ef41Sopenharmony_ci {
2161cb0ef41Sopenharmony_ci     int ret;
2171cb0ef41Sopenharmony_ci     z_stream strm, copy;
2181cb0ef41Sopenharmony_ci@@ -394,7 +416,7 @@ local void cover_wrap(void)
2191cb0ef41Sopenharmony_ci     ret = inflate(Z_NULL, 0);                   assert(ret == Z_STREAM_ERROR);
2201cb0ef41Sopenharmony_ci     ret = inflateEnd(Z_NULL);                   assert(ret == Z_STREAM_ERROR);
2211cb0ef41Sopenharmony_ci     ret = inflateCopy(Z_NULL, Z_NULL);          assert(ret == Z_STREAM_ERROR);
2221cb0ef41Sopenharmony_ci-    fputs("inflate bad parameters\n", stderr);
2231cb0ef41Sopenharmony_ci+    std::cout << "inflate bad parameters" << std::endl;
2241cb0ef41Sopenharmony_ci 
2251cb0ef41Sopenharmony_ci     inf("1f 8b 0 0", "bad gzip method", 0, 31, 0, Z_DATA_ERROR);
2261cb0ef41Sopenharmony_ci     inf("1f 8b 8 80", "bad gzip flags", 0, 31, 0, Z_DATA_ERROR);
2271cb0ef41Sopenharmony_ci@@ -415,9 +437,9 @@ local void cover_wrap(void)
2281cb0ef41Sopenharmony_ci     strm.next_in = Z_NULL;
2291cb0ef41Sopenharmony_ci     ret = inflateInit2(&strm, -8);
2301cb0ef41Sopenharmony_ci     strm.avail_in = 2;
2311cb0ef41Sopenharmony_ci-    strm.next_in = (void *)"\x63";
2321cb0ef41Sopenharmony_ci+    strm.next_in = (Bytef *)"\x63";
2331cb0ef41Sopenharmony_ci     strm.avail_out = 1;
2341cb0ef41Sopenharmony_ci-    strm.next_out = (void *)&ret;
2351cb0ef41Sopenharmony_ci+    strm.next_out = (Bytef *)&ret;
2361cb0ef41Sopenharmony_ci     mem_limit(&strm, 1);
2371cb0ef41Sopenharmony_ci     ret = inflate(&strm, Z_NO_FLUSH);           assert(ret == Z_MEM_ERROR);
2381cb0ef41Sopenharmony_ci     ret = inflate(&strm, Z_NO_FLUSH);           assert(ret == Z_MEM_ERROR);
2391cb0ef41Sopenharmony_ci@@ -428,11 +450,11 @@ local void cover_wrap(void)
2401cb0ef41Sopenharmony_ci     mem_limit(&strm, (sizeof(struct inflate_state) << 1) + 256);
2411cb0ef41Sopenharmony_ci     ret = inflatePrime(&strm, 16, 0);           assert(ret == Z_OK);
2421cb0ef41Sopenharmony_ci     strm.avail_in = 2;
2431cb0ef41Sopenharmony_ci-    strm.next_in = (void *)"\x80";
2441cb0ef41Sopenharmony_ci+    strm.next_in = (Bytef *)"\x80";
2451cb0ef41Sopenharmony_ci     ret = inflateSync(&strm);                   assert(ret == Z_DATA_ERROR);
2461cb0ef41Sopenharmony_ci     ret = inflate(&strm, Z_NO_FLUSH);           assert(ret == Z_STREAM_ERROR);
2471cb0ef41Sopenharmony_ci     strm.avail_in = 4;
2481cb0ef41Sopenharmony_ci-    strm.next_in = (void *)"\0\0\xff\xff";
2491cb0ef41Sopenharmony_ci+    strm.next_in = (Bytef *)"\0\0\xff\xff";
2501cb0ef41Sopenharmony_ci     ret = inflateSync(&strm);                   assert(ret == Z_OK);
2511cb0ef41Sopenharmony_ci     (void)inflateSyncPoint(&strm);
2521cb0ef41Sopenharmony_ci     ret = inflateCopy(&copy, &strm);            assert(ret == Z_MEM_ERROR);
2531cb0ef41Sopenharmony_ci@@ -454,7 +476,7 @@ local unsigned pull(void *desc, unsigned char **buf)
2541cb0ef41Sopenharmony_ci         next = 0;
2551cb0ef41Sopenharmony_ci         return 0;   /* no input (already provided at next_in) */
2561cb0ef41Sopenharmony_ci     }
2571cb0ef41Sopenharmony_ci-    state = (void *)((z_stream *)desc)->state;
2581cb0ef41Sopenharmony_ci+    state = reinterpret_cast<struct inflate_state *>(((z_stream *)desc)->state);
2591cb0ef41Sopenharmony_ci     if (state != Z_NULL)
2601cb0ef41Sopenharmony_ci         state->mode = SYNC;     /* force an otherwise impossible situation */
2611cb0ef41Sopenharmony_ci     return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
2621cb0ef41Sopenharmony_ci@@ -467,7 +489,7 @@ local int push(void *desc, unsigned char *buf, unsigned len)
2631cb0ef41Sopenharmony_ci }
2641cb0ef41Sopenharmony_ci 
2651cb0ef41Sopenharmony_ci /* cover inflateBack() up to common deflate data cases and after those */
2661cb0ef41Sopenharmony_ci-local void cover_back(void)
2671cb0ef41Sopenharmony_ci+void cover_back(void)
2681cb0ef41Sopenharmony_ci {
2691cb0ef41Sopenharmony_ci     int ret;
2701cb0ef41Sopenharmony_ci     z_stream strm;
2711cb0ef41Sopenharmony_ci@@ -479,17 +501,17 @@ local void cover_back(void)
2721cb0ef41Sopenharmony_ci     ret = inflateBack(Z_NULL, Z_NULL, Z_NULL, Z_NULL, Z_NULL);
2731cb0ef41Sopenharmony_ci                                                 assert(ret == Z_STREAM_ERROR);
2741cb0ef41Sopenharmony_ci     ret = inflateBackEnd(Z_NULL);               assert(ret == Z_STREAM_ERROR);
2751cb0ef41Sopenharmony_ci-    fputs("inflateBack bad parameters\n", stderr);
2761cb0ef41Sopenharmony_ci+    std::cout << "inflateBack bad parameters" << std::endl;;
2771cb0ef41Sopenharmony_ci 
2781cb0ef41Sopenharmony_ci     mem_setup(&strm);
2791cb0ef41Sopenharmony_ci     ret = inflateBackInit(&strm, 15, win);      assert(ret == Z_OK);
2801cb0ef41Sopenharmony_ci     strm.avail_in = 2;
2811cb0ef41Sopenharmony_ci-    strm.next_in = (void *)"\x03";
2821cb0ef41Sopenharmony_ci+    strm.next_in = (Bytef *)"\x03";
2831cb0ef41Sopenharmony_ci     ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL);
2841cb0ef41Sopenharmony_ci                                                 assert(ret == Z_STREAM_END);
2851cb0ef41Sopenharmony_ci         /* force output error */
2861cb0ef41Sopenharmony_ci     strm.avail_in = 3;
2871cb0ef41Sopenharmony_ci-    strm.next_in = (void *)"\x63\x00";
2881cb0ef41Sopenharmony_ci+    strm.next_in = (Bytef *)"\x63\x00";
2891cb0ef41Sopenharmony_ci     ret = inflateBack(&strm, pull, Z_NULL, push, &strm);
2901cb0ef41Sopenharmony_ci                                                 assert(ret == Z_BUF_ERROR);
2911cb0ef41Sopenharmony_ci         /* force mode error by mucking with state */
2921cb0ef41Sopenharmony_ci@@ -500,11 +522,11 @@ local void cover_back(void)
2931cb0ef41Sopenharmony_ci 
2941cb0ef41Sopenharmony_ci     ret = inflateBackInit(&strm, 15, win);      assert(ret == Z_OK);
2951cb0ef41Sopenharmony_ci     ret = inflateBackEnd(&strm);                assert(ret == Z_OK);
2961cb0ef41Sopenharmony_ci-    fputs("inflateBack built-in memory routines\n", stderr);
2971cb0ef41Sopenharmony_ci+    std::cout << "inflateBack built-in memory routines" << std::endl;;
2981cb0ef41Sopenharmony_ci }
2991cb0ef41Sopenharmony_ci 
3001cb0ef41Sopenharmony_ci /* do a raw inflate of data in hexadecimal with both inflate and inflateBack */
3011cb0ef41Sopenharmony_ci-local int try(char *hex, char *id, int err)
3021cb0ef41Sopenharmony_ci+local int try(const char *hex, const char *id, int err)
3031cb0ef41Sopenharmony_ci {
3041cb0ef41Sopenharmony_ci     int ret;
3051cb0ef41Sopenharmony_ci     unsigned len, size;
3061cb0ef41Sopenharmony_ci@@ -518,11 +540,11 @@ local int try(char *hex, char *id, int err)
3071cb0ef41Sopenharmony_ci 
3081cb0ef41Sopenharmony_ci     /* allocate work areas */
3091cb0ef41Sopenharmony_ci     size = len << 3;
3101cb0ef41Sopenharmony_ci-    out = malloc(size);
3111cb0ef41Sopenharmony_ci+    out = static_cast<unsigned char *>(malloc(size));
3121cb0ef41Sopenharmony_ci     assert(out != NULL);
3131cb0ef41Sopenharmony_ci-    win = malloc(32768);
3141cb0ef41Sopenharmony_ci+    win = static_cast<unsigned char *>(malloc(32768));
3151cb0ef41Sopenharmony_ci     assert(win != NULL);
3161cb0ef41Sopenharmony_ci-    prefix = malloc(strlen(id) + 6);
3171cb0ef41Sopenharmony_ci+    prefix = static_cast<char *>(malloc(strlen(id) + 6));
3181cb0ef41Sopenharmony_ci     assert(prefix != NULL);
3191cb0ef41Sopenharmony_ci 
3201cb0ef41Sopenharmony_ci     /* first with inflate */
3211cb0ef41Sopenharmony_ci@@ -578,7 +600,7 @@ local int try(char *hex, char *id, int err)
3221cb0ef41Sopenharmony_ci }
3231cb0ef41Sopenharmony_ci 
3241cb0ef41Sopenharmony_ci /* cover deflate data cases in both inflate() and inflateBack() */
3251cb0ef41Sopenharmony_ci-local void cover_inflate(void)
3261cb0ef41Sopenharmony_ci+void cover_inflate(void)
3271cb0ef41Sopenharmony_ci {
3281cb0ef41Sopenharmony_ci     try("0 0 0 0 0", "invalid stored block lengths", 1);
3291cb0ef41Sopenharmony_ci     try("3 0", "fixed", 0);
3301cb0ef41Sopenharmony_ci@@ -613,32 +635,33 @@ local void cover_inflate(void)
3311cb0ef41Sopenharmony_ci     inf("63 18 5 40 c 0", "window wrap", 3, -8, 300, Z_OK);
3321cb0ef41Sopenharmony_ci }
3331cb0ef41Sopenharmony_ci 
3341cb0ef41Sopenharmony_ci+/* XXX(cavalcantii): fix linking error due inflate_table. */
3351cb0ef41Sopenharmony_ci /* cover remaining lines in inftrees.c */
3361cb0ef41Sopenharmony_ci-local void cover_trees(void)
3371cb0ef41Sopenharmony_ci-{
3381cb0ef41Sopenharmony_ci-    int ret;
3391cb0ef41Sopenharmony_ci-    unsigned bits;
3401cb0ef41Sopenharmony_ci-    unsigned short lens[16], work[16];
3411cb0ef41Sopenharmony_ci-    code *next, table[ENOUGH_DISTS];
3421cb0ef41Sopenharmony_ci-
3431cb0ef41Sopenharmony_ci-    /* we need to call inflate_table() directly in order to manifest not-
3441cb0ef41Sopenharmony_ci-       enough errors, since zlib insures that enough is always enough */
3451cb0ef41Sopenharmony_ci-    for (bits = 0; bits < 15; bits++)
3461cb0ef41Sopenharmony_ci-        lens[bits] = (unsigned short)(bits + 1);
3471cb0ef41Sopenharmony_ci-    lens[15] = 15;
3481cb0ef41Sopenharmony_ci-    next = table;
3491cb0ef41Sopenharmony_ci-    bits = 15;
3501cb0ef41Sopenharmony_ci-    ret = inflate_table(DISTS, lens, 16, &next, &bits, work);
3511cb0ef41Sopenharmony_ci-                                                assert(ret == 1);
3521cb0ef41Sopenharmony_ci-    next = table;
3531cb0ef41Sopenharmony_ci-    bits = 1;
3541cb0ef41Sopenharmony_ci-    ret = inflate_table(DISTS, lens, 16, &next, &bits, work);
3551cb0ef41Sopenharmony_ci-                                                assert(ret == 1);
3561cb0ef41Sopenharmony_ci-    fputs("inflate_table not enough errors\n", stderr);
3571cb0ef41Sopenharmony_ci-}
3581cb0ef41Sopenharmony_ci+/* void cover_trees(void) */
3591cb0ef41Sopenharmony_ci+/* { */
3601cb0ef41Sopenharmony_ci+/*     int ret; */
3611cb0ef41Sopenharmony_ci+/*     unsigned bits; */
3621cb0ef41Sopenharmony_ci+/*     unsigned short lens[16], work[16]; */
3631cb0ef41Sopenharmony_ci+/*     code *next, table[ENOUGH_DISTS]; */
3641cb0ef41Sopenharmony_ci+
3651cb0ef41Sopenharmony_ci+/*     /\* we need to call inflate_table() directly in order to manifest not- */
3661cb0ef41Sopenharmony_ci+/*        enough errors, since zlib insures that enough is always enough *\/ */
3671cb0ef41Sopenharmony_ci+/*     for (bits = 0; bits < 15; bits++) */
3681cb0ef41Sopenharmony_ci+/*         lens[bits] = (unsigned short)(bits + 1); */
3691cb0ef41Sopenharmony_ci+/*     lens[15] = 15; */
3701cb0ef41Sopenharmony_ci+/*     next = table; */
3711cb0ef41Sopenharmony_ci+/*     bits = 15; */
3721cb0ef41Sopenharmony_ci+/*     ret = inflate_table(DISTS, lens, 16, &next, &bits, work); */
3731cb0ef41Sopenharmony_ci+/*                                                 assert(ret == 1); */
3741cb0ef41Sopenharmony_ci+/*     next = table; */
3751cb0ef41Sopenharmony_ci+/*     bits = 1; */
3761cb0ef41Sopenharmony_ci+/*     ret = inflate_table(DISTS, lens, 16, &next, &bits, work); */
3771cb0ef41Sopenharmony_ci+/*                                                 assert(ret == 1); */
3781cb0ef41Sopenharmony_ci+/*     fputs("inflate_table not enough errors\n", stderr); */
3791cb0ef41Sopenharmony_ci+/* } */
3801cb0ef41Sopenharmony_ci 
3811cb0ef41Sopenharmony_ci /* cover remaining inffast.c decoding and window copying */
3821cb0ef41Sopenharmony_ci-local void cover_fast(void)
3831cb0ef41Sopenharmony_ci+void cover_fast(void)
3841cb0ef41Sopenharmony_ci {
3851cb0ef41Sopenharmony_ci     inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68"
3861cb0ef41Sopenharmony_ci         " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR);
3871cb0ef41Sopenharmony_ci@@ -658,14 +681,4 @@ local void cover_fast(void)
3881cb0ef41Sopenharmony_ci         Z_STREAM_END);
3891cb0ef41Sopenharmony_ci }
3901cb0ef41Sopenharmony_ci 
3911cb0ef41Sopenharmony_ci-int main(void)
3921cb0ef41Sopenharmony_ci-{
3931cb0ef41Sopenharmony_ci-    fprintf(stderr, "%s\n", zlibVersion());
3941cb0ef41Sopenharmony_ci-    cover_support();
3951cb0ef41Sopenharmony_ci-    cover_wrap();
3961cb0ef41Sopenharmony_ci-    cover_back();
3971cb0ef41Sopenharmony_ci-    cover_inflate();
3981cb0ef41Sopenharmony_ci-    cover_trees();
3991cb0ef41Sopenharmony_ci-    cover_fast();
4001cb0ef41Sopenharmony_ci-    return 0;
4011cb0ef41Sopenharmony_ci-}
4021cb0ef41Sopenharmony_ci+// clang-format on
4031cb0ef41Sopenharmony_ci-- 
4041cb0ef41Sopenharmony_ci2.21.1 (Apple Git-122.3)
4051cb0ef41Sopenharmony_ci
406