DEFAULT_DISPLAYLEVEL; /* no dict */
void* const dictBuffer = malloc(maxDictSize);
- dictInfo* dInfo;
+ dictInfo* dInfo = NULL;
/* Checks */
if (!dictBuffer)
/* Local variables */
size_t totalCompressedSize = 0;
size_t totalOriginalSize = 0;
- unsigned hasDict = dInfo->dictSize > 0 ? 1 : 0;
+ const unsigned hasDict = dInfo->dictSize > 0 ? 1 : 0;
double cRatio;
size_t dstCapacity;
int i;
/* Pointers */
- ZSTD_CCtx* cctx;
- ZSTD_CDict *cdict;
- size_t *offsets;
- void* dst;
+ ZSTD_CDict *cdict = NULL;
+ ZSTD_CCtx* cctx = NULL;
+ size_t *offsets = NULL;
+ void* dst = NULL;
/* Allocate dst with enough space to compress the maximum sized sample */
{
cctx = ZSTD_createCCtx();
if(!cctx || !dst) {
cRatio = -1;
- goto _nodictCleanup;
+ goto _cleanup;
}
/* Create CDict if there's a dictionary stored on buffer */
cdict = ZSTD_createCDict(dInfo->dictBuffer, dInfo->dictSize, compressionLevel);
if(!cdict) {
cRatio = -1;
- goto _dictCleanup;
+ goto _cleanup;
}
}
}
if (ZSTD_isError(compressedSize)) {
cRatio = -1;
- if(hasDict) goto _dictCleanup;
- else goto _nodictCleanup;
+ goto _cleanup;
}
totalCompressedSize += compressedSize;
}
DISPLAYLEVEL(2, "compressed size is %lu\n", totalCompressedSize);
cRatio = (double)totalOriginalSize/(double)totalCompressedSize;
-_dictCleanup:
- ZSTD_freeCDict(cdict);
-
-_nodictCleanup:
+_cleanup:
free(dst);
free(offsets);
ZSTD_freeCCtx(cctx);
-
+ ZSTD_freeCDict(cdict);
return cRatio;
}
DISPLAYLEVEL(2, "%s took %f seconds to execute \n", name, timeSec);
/* Calculate compression ratio */
- double cRatio = compressWithDict(srcInfo, dInfo, cLevel, displayLevel);
+ const double cRatio = compressWithDict(srcInfo, dInfo, cLevel, displayLevel);
if (cRatio < 0) {
DISPLAYLEVEL(1, "Compressing with %s dictionary does not work\n", name);
result = 1;