introduced CHECK_F
This commit is contained in:
parent
ff306ae2f6
commit
3e21ec5b01
@ -42,10 +42,11 @@
|
|||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Common macros
|
* shared macros
|
||||||
***************************************/
|
***************************************/
|
||||||
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
||||||
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
||||||
|
#define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
|
@ -1097,7 +1097,7 @@ static void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx,
|
|||||||
|
|
||||||
if (ip <= ilimit) {
|
if (ip <= ilimit) {
|
||||||
/* Fill Table */
|
/* Fill Table */
|
||||||
hashTable[ZSTD_hashPtr(base+current+2, hBits, mls)] = current+2;
|
hashTable[ZSTD_hashPtr(base+current+2, hBits, mls)] = current+2;
|
||||||
hashTable[ZSTD_hashPtr(ip-2, hBits, mls)] = (U32)(ip-2-base);
|
hashTable[ZSTD_hashPtr(ip-2, hBits, mls)] = (U32)(ip-2-base);
|
||||||
/* check immediate repcode */
|
/* check immediate repcode */
|
||||||
while (ip <= ilimit) {
|
while (ip <= ilimit) {
|
||||||
@ -2534,9 +2534,9 @@ static size_t ZSTD_compress_insertDictionary(ZSTD_CCtx* zc, const void* dict, si
|
|||||||
zc->dictID = zc->params.fParams.noDictIDFlag ? 0 : MEM_readLE32((const char*)dict+4);
|
zc->dictID = zc->params.fParams.noDictIDFlag ? 0 : MEM_readLE32((const char*)dict+4);
|
||||||
|
|
||||||
/* known magic number : dict is parsed for entropy stats and content */
|
/* known magic number : dict is parsed for entropy stats and content */
|
||||||
{ size_t const eSize_8 = ZSTD_loadDictEntropyStats(zc, (const char*)dict+8 /* skip dictHeader */, dictSize-8);
|
{ size_t const loadError = ZSTD_loadDictEntropyStats(zc, (const char*)dict+8 /* skip dictHeader */, dictSize-8);
|
||||||
size_t const eSize = eSize_8 + 8;
|
size_t const eSize = loadError + 8;
|
||||||
if (ZSTD_isError(eSize_8)) return eSize_8;
|
if (ZSTD_isError(loadError)) return loadError;
|
||||||
return ZSTD_loadDictionaryContent(zc, (const char*)dict+eSize, dictSize-eSize);
|
return ZSTD_loadDictionaryContent(zc, (const char*)dict+eSize, dictSize-eSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2549,9 +2549,7 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
|
|||||||
ZSTD_parameters params, U64 pledgedSrcSize)
|
ZSTD_parameters params, U64 pledgedSrcSize)
|
||||||
{
|
{
|
||||||
ZSTD_compResetPolicy_e const crp = dictSize ? ZSTDcrp_fullReset : ZSTDcrp_continue;
|
ZSTD_compResetPolicy_e const crp = dictSize ? ZSTDcrp_fullReset : ZSTDcrp_continue;
|
||||||
size_t const resetError = ZSTD_resetCCtx_advanced(cctx, params, pledgedSrcSize, crp);
|
CHECK_F(ZSTD_resetCCtx_advanced(cctx, params, pledgedSrcSize, crp));
|
||||||
if (ZSTD_isError(resetError)) return resetError;
|
|
||||||
|
|
||||||
return ZSTD_compress_insertDictionary(cctx, dict, dictSize);
|
return ZSTD_compress_insertDictionary(cctx, dict, dictSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2563,9 +2561,7 @@ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx,
|
|||||||
ZSTD_parameters params, unsigned long long pledgedSrcSize)
|
ZSTD_parameters params, unsigned long long pledgedSrcSize)
|
||||||
{
|
{
|
||||||
/* compression parameters verification and optimization */
|
/* compression parameters verification and optimization */
|
||||||
size_t const errorCode = ZSTD_checkCParams_advanced(params.cParams, pledgedSrcSize);
|
CHECK_F(ZSTD_checkCParams_advanced(params.cParams, pledgedSrcSize));
|
||||||
if (ZSTD_isError(errorCode)) return errorCode;
|
|
||||||
|
|
||||||
return ZSTD_compressBegin_internal(cctx, dict, dictSize, params, pledgedSrcSize);
|
return ZSTD_compressBegin_internal(cctx, dict, dictSize, params, pledgedSrcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2643,9 +2639,7 @@ static size_t ZSTD_compress_internal (ZSTD_CCtx* cctx,
|
|||||||
const void* dict,size_t dictSize,
|
const void* dict,size_t dictSize,
|
||||||
ZSTD_parameters params)
|
ZSTD_parameters params)
|
||||||
{
|
{
|
||||||
size_t const errorCode = ZSTD_compressBegin_internal(cctx, dict, dictSize, params, srcSize);
|
CHECK_F(ZSTD_compressBegin_internal(cctx, dict, dictSize, params, srcSize));
|
||||||
if(ZSTD_isError(errorCode)) return errorCode;
|
|
||||||
|
|
||||||
return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
|
return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2655,8 +2649,7 @@ size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
|
|||||||
const void* dict,size_t dictSize,
|
const void* dict,size_t dictSize,
|
||||||
ZSTD_parameters params)
|
ZSTD_parameters params)
|
||||||
{
|
{
|
||||||
size_t const errorCode = ZSTD_checkCParams_advanced(params.cParams, srcSize);
|
CHECK_F(ZSTD_checkCParams_advanced(params.cParams, srcSize));
|
||||||
if (ZSTD_isError(errorCode)) return errorCode;
|
|
||||||
return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params);
|
return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2854,8 +2847,7 @@ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|||||||
if (zcs->outBuff == NULL) return ERROR(memory_allocation);
|
if (zcs->outBuff == NULL) return ERROR(memory_allocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ size_t const errorCode = ZSTD_compressBegin_advanced(zcs->zc, dict, dictSize, params, pledgedSrcSize);
|
CHECK_F(ZSTD_compressBegin_advanced(zcs->zc, dict, dictSize, params, pledgedSrcSize));
|
||||||
if (ZSTD_isError(errorCode)) return errorCode; }
|
|
||||||
|
|
||||||
zcs->inToCompress = 0;
|
zcs->inToCompress = 0;
|
||||||
zcs->inBuffPos = 0;
|
zcs->inBuffPos = 0;
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
# define ZSTD_LEGACY_SUPPORT 0
|
# define ZSTD_LEGACY_SUPPORT 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* MAXWINDOWSIZE_DEFAULT :
|
* MAXWINDOWSIZE_DEFAULT :
|
||||||
* maximum window size accepted by DStream, by default.
|
* maximum window size accepted by DStream, by default.
|
||||||
@ -123,7 +122,7 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx)
|
|||||||
dctx->hufTable[0] = (HUF_DTable)((HufLog)*0x1000001);
|
dctx->hufTable[0] = (HUF_DTable)((HufLog)*0x1000001);
|
||||||
dctx->litEntropy = dctx->fseEntropy = 0;
|
dctx->litEntropy = dctx->fseEntropy = 0;
|
||||||
dctx->dictID = 0;
|
dctx->dictID = 0;
|
||||||
MEM_STATIC_ASSERT(sizeof(dctx->rep)==sizeof(repStartValue));
|
MEM_STATIC_ASSERT(sizeof(dctx->rep) == sizeof(repStartValue));
|
||||||
memcpy(dctx->rep, repStartValue, sizeof(repStartValue));
|
memcpy(dctx->rep, repStartValue, sizeof(repStartValue));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -135,7 +134,7 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
|
|||||||
if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
|
if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
|
||||||
if (!customMem.customAlloc || !customMem.customFree) return NULL;
|
if (!customMem.customAlloc || !customMem.customFree) return NULL;
|
||||||
|
|
||||||
dctx = (ZSTD_DCtx*) ZSTD_malloc(sizeof(ZSTD_DCtx), customMem);
|
dctx = (ZSTD_DCtx*)ZSTD_malloc(sizeof(ZSTD_DCtx), customMem);
|
||||||
if (!dctx) return NULL;
|
if (!dctx) return NULL;
|
||||||
memcpy(&dctx->customMem, &customMem, sizeof(customMem));
|
memcpy(&dctx->customMem, &customMem, sizeof(customMem));
|
||||||
ZSTD_decompressBegin(dctx);
|
ZSTD_decompressBegin(dctx);
|
||||||
@ -454,7 +453,6 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
|||||||
default:
|
default:
|
||||||
return ERROR(corruption_detected); /* impossible */
|
return ERROR(corruption_detected); /* impossible */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,11 +840,9 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
|||||||
|
|
||||||
/* Frame Header */
|
/* Frame Header */
|
||||||
{ size_t const frameHeaderSize = ZSTD_frameHeaderSize(src, ZSTD_frameHeaderSize_prefix);
|
{ size_t const frameHeaderSize = ZSTD_frameHeaderSize(src, ZSTD_frameHeaderSize_prefix);
|
||||||
size_t result;
|
|
||||||
if (ZSTD_isError(frameHeaderSize)) return frameHeaderSize;
|
if (ZSTD_isError(frameHeaderSize)) return frameHeaderSize;
|
||||||
if (srcSize < frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
|
if (srcSize < frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
|
||||||
result = ZSTD_decodeFrameHeader(dctx, src, frameHeaderSize);
|
CHECK_F(ZSTD_decodeFrameHeader(dctx, src, frameHeaderSize));
|
||||||
if (ZSTD_isError(result)) return result;
|
|
||||||
ip += frameHeaderSize; remainingSize -= frameHeaderSize;
|
ip += frameHeaderSize; remainingSize -= frameHeaderSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,14 +1005,12 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
|
|||||||
dctx->expected = 0; /* not necessary to copy more */
|
dctx->expected = 0; /* not necessary to copy more */
|
||||||
|
|
||||||
case ZSTDds_decodeFrameHeader:
|
case ZSTDds_decodeFrameHeader:
|
||||||
{ size_t result;
|
memcpy(dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected);
|
||||||
memcpy(dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected);
|
CHECK_F(ZSTD_decodeFrameHeader(dctx, dctx->headerBuffer, dctx->headerSize));
|
||||||
result = ZSTD_decodeFrameHeader(dctx, dctx->headerBuffer, dctx->headerSize);
|
dctx->expected = ZSTD_blockHeaderSize;
|
||||||
if (ZSTD_isError(result)) return result;
|
dctx->stage = ZSTDds_decodeBlockHeader;
|
||||||
dctx->expected = ZSTD_blockHeaderSize;
|
return 0;
|
||||||
dctx->stage = ZSTDds_decodeBlockHeader;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case ZSTDds_decodeBlockHeader:
|
case ZSTDds_decodeBlockHeader:
|
||||||
{ blockProperties_t bp;
|
{ blockProperties_t bp;
|
||||||
size_t const cBlockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp);
|
size_t const cBlockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp);
|
||||||
@ -1185,8 +1179,7 @@ static size_t ZSTD_decompress_insertDictionary(ZSTD_DCtx* dctx, const void* dict
|
|||||||
|
|
||||||
size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize)
|
size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize)
|
||||||
{
|
{
|
||||||
{ size_t const errorCode = ZSTD_decompressBegin(dctx);
|
CHECK_F(ZSTD_decompressBegin(dctx));
|
||||||
if (ZSTD_isError(errorCode)) return errorCode; }
|
|
||||||
|
|
||||||
if (dict && dictSize) {
|
if (dict && dictSize) {
|
||||||
size_t const errorCode = ZSTD_decompress_insertDictionary(dctx, dict, dictSize);
|
size_t const errorCode = ZSTD_decompress_insertDictionary(dctx, dict, dictSize);
|
||||||
@ -1428,10 +1421,8 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|||||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
||||||
{ U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
|
{ U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
|
||||||
if (legacyVersion) {
|
if (legacyVersion) {
|
||||||
size_t initResult;
|
CHECK_F(ZSTD_initLegacyStream(&zds->legacyContext, zds->previousLegacyVersion, legacyVersion,
|
||||||
initResult = ZSTD_initLegacyStream(&zds->legacyContext, zds->previousLegacyVersion, legacyVersion,
|
zds->dictContent, zds->dictSize));
|
||||||
zds->dictContent, zds->dictSize);
|
|
||||||
if (ZSTD_isError(initResult)) return initResult;
|
|
||||||
zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
|
zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
|
||||||
return ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
|
return ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
|
||||||
} else {
|
} else {
|
||||||
@ -1455,11 +1446,9 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|||||||
/* Consume header */
|
/* Consume header */
|
||||||
ZSTD_decompressBegin_usingDict(zds->zd, zds->dictContent, zds->dictSize);
|
ZSTD_decompressBegin_usingDict(zds->zd, zds->dictContent, zds->dictSize);
|
||||||
{ size_t const h1Size = ZSTD_nextSrcSizeToDecompress(zds->zd); /* == ZSTD_frameHeaderSize_prefix */
|
{ size_t const h1Size = ZSTD_nextSrcSizeToDecompress(zds->zd); /* == ZSTD_frameHeaderSize_prefix */
|
||||||
size_t const h1Result = ZSTD_decompressContinue(zds->zd, NULL, 0, zds->headerBuffer, h1Size);
|
CHECK_F(ZSTD_decompressContinue(zds->zd, NULL, 0, zds->headerBuffer, h1Size));
|
||||||
if (ZSTD_isError(h1Result)) return h1Result; /* should not happen : already checked */
|
|
||||||
{ size_t const h2Size = ZSTD_nextSrcSizeToDecompress(zds->zd);
|
{ size_t const h2Size = ZSTD_nextSrcSizeToDecompress(zds->zd);
|
||||||
size_t const h2Result = ZSTD_decompressContinue(zds->zd, NULL, 0, zds->headerBuffer+h1Size, h2Size);
|
CHECK_F(ZSTD_decompressContinue(zds->zd, NULL, 0, zds->headerBuffer+h1Size, h2Size));
|
||||||
if (ZSTD_isError(h2Result)) return h2Result;
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN);
|
zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN);
|
||||||
|
Loading…
Reference in New Issue
Block a user