From: W. Felix Handte Date: Fri, 1 May 2020 16:24:51 +0000 (-0400) Subject: Fix Up Some Pointer Handling in Tests X-Git-Tag: v1.4.5^2~50^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dacbcd2cc1741ba5aaf7eb8f3f4502b4d2144b26;p=thirdparty%2Fzstd.git Fix Up Some Pointer Handling in Tests --- diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 700cb5771..52bc02c48 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -28,6 +28,7 @@ #undef NDEBUG #include #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"); diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 3fc96eb11..79d5a8281 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -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");