Fix Up Some Pointer Handling in Tests

This commit is contained in:
W. Felix Handte 2020-05-01 12:24:51 -04:00
parent 3764859060
commit dacbcd2cc1
2 changed files with 28 additions and 7 deletions

View 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");

View 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");