]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix Up Some Pointer Handling in Tests
authorW. Felix Handte <w@felixhandte.com>
Fri, 1 May 2020 16:24:51 +0000 (12:24 -0400)
committerW. Felix Handte <w@felixhandte.com>
Mon, 4 May 2020 14:59:15 +0000 (10:59 -0400)
tests/fuzzer.c
tests/zstreamtest.c

index 700cb5771600a931ce59d2c4314dab09beb45547..52bc02c48a644cba0a7b7c2de0aa5c6bc616d238 100644 (file)
@@ -28,6 +28,7 @@
 #undef NDEBUG
 #include <assert.h>
 #define ZSTD_STATIC_LINKING_ONLY  /* ZSTD_compressContinue, ZSTD_compressBlock */
+#include "debug.h"        /* DEBUG_STATIC_ASSERT */
 #include "fse.h"
 #include "zstd.h"         /* ZSTD_VERSION_STRING */
 #include "zstd_errors.h"  /* ZSTD_getErrorCode */
@@ -456,10 +457,30 @@ static int basicUnitTests(U32 const seed, double compressibility)
 
     DISPLAYLEVEL(3, "test%3i : misc unaccounted for zstd symbols : ", testNb++);
     {
-        DISPLAYLEVEL(3, "%p ", ZSTD_getDictID_fromDDict);
-        DISPLAYLEVEL(3, "%p ", ZSTD_createDStream_advanced);
-        DISPLAYLEVEL(3, "%p ", ZSTD_copyDCtx);
-        DISPLAYLEVEL(3, "%p ", ZSTD_nextInputType);
+        /* %p takes a void*. In ISO C, it's illegal to cast a function pointer
+         * to a data pointer. (Although in POSIX you're required to be allowed
+         * to do it...) So we have to fall back to our trusty friend memcpy. */
+        unsigned (* const funcptr_getDictID)(const ZSTD_DDict* ddict) =
+            ZSTD_getDictID_fromDDict;
+        ZSTD_DStream* (* const funcptr_createDStream)(
+            ZSTD_customMem customMem) = ZSTD_createDStream_advanced;
+        void (* const funcptr_copyDCtx)(
+            ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx) = ZSTD_copyDCtx;
+        ZSTD_nextInputType_e (* const funcptr_nextInputType)(ZSTD_DCtx* dctx) =
+            ZSTD_nextInputType;
+        const void *voidptr_getDictID;
+        const void *voidptr_createDStream;
+        const void *voidptr_copyDCtx;
+        const void *voidptr_nextInputType;
+        DEBUG_STATIC_ASSERT(sizeof(funcptr_getDictID) == sizeof(voidptr_getDictID));
+        memcpy(&voidptr_getDictID    , &funcptr_getDictID    , sizeof(void*));
+        memcpy(&voidptr_createDStream, &funcptr_createDStream, sizeof(void*));
+        memcpy(&voidptr_copyDCtx     , &funcptr_copyDCtx     , sizeof(void*));
+        memcpy(&voidptr_nextInputType, &funcptr_nextInputType, sizeof(void*));
+        DISPLAYLEVEL(3, "%p ", voidptr_getDictID);
+        DISPLAYLEVEL(3, "%p ", voidptr_createDStream);
+        DISPLAYLEVEL(3, "%p ", voidptr_copyDCtx);
+        DISPLAYLEVEL(3, "%p ", voidptr_nextInputType);
     }
     DISPLAYLEVEL(3, ": OK \n");
 
index 3fc96eb11bfe827520a3837b644b145af30d9465..79d5a8281bb523115cfc3221365c5dfd09eb6f86 100644 (file)
@@ -1452,12 +1452,12 @@ static int basicUnitTests(U32 seed, double compressibility)
 
         /* and includes a very long backref */
         cursegmentlen = 128;
-        memcpy(inbuf + inbufpos, dictionary.start + 256, cursegmentlen);
+        memcpy(inbuf + inbufpos, (BYTE*)dictionary.start + 256, cursegmentlen);
         inbufpos += cursegmentlen;
 
         /* and includes a very long backref */
         cursegmentlen = 128;
-        memcpy(inbuf + inbufpos, dictionary.start + 128, cursegmentlen);
+        memcpy(inbuf + inbufpos, (BYTE*)dictionary.start + 128, cursegmentlen);
         inbufpos += cursegmentlen;
 
         ret = ZSTD_compress_usingCDict(zc, outbuf, outbufsize, inbuf, inbufpos, cdict);
@@ -1500,7 +1500,7 @@ static int basicUnitTests(U32 seed, double compressibility)
         }
         /* Write several very long offset matches into the dictionary */
         for (offset = 1024; offset >= 0; offset -= 128) {
-          ZSTD_inBuffer in = {dictionary.start + offset, 128, 0};
+          ZSTD_inBuffer in = {(BYTE*)dictionary.start + offset, 128, 0};
           ZSTD_EndDirective flush = offset > 0 ? ZSTD_e_continue : ZSTD_e_end;
           CHECK_Z(ZSTD_compressStream2(zc, &out, &in, flush));
           CHECK(in.pos != in.size, "input not fully consumed");