From: Yann Collet Date: Wed, 22 Jun 2016 09:05:34 +0000 (+0200) Subject: Fixed : dictBuilder fails if first sample is too small X-Git-Tag: v0.7.1~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23042929daf5fb207bfadaffdd85325bfbd16e24;p=thirdparty%2Fzstd.git Fixed : dictBuilder fails if first sample is too small --- diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 0814581fe..031509453 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -584,48 +584,51 @@ static void ZDICT_countEStats(EStats_ress_t esr, U32* countLit, U32* offsetcodeCount, U32* matchlengthCount, U32* litlengthCount, U32* repOffsets, const void* src, size_t srcSize) { - const seqStore_t* seqStorePtr; + size_t cSize; if (srcSize > ZSTD_BLOCKSIZE_MAX) srcSize = ZSTD_BLOCKSIZE_MAX; /* protection vs large samples */ ZSTD_copyCCtx(esr.zc, esr.ref); - ZSTD_compressBlock(esr.zc, esr.workPlace, ZSTD_BLOCKSIZE_MAX, src, srcSize); - seqStorePtr = ZSTD_getSeqStore(esr.zc); + cSize = ZSTD_compressBlock(esr.zc, esr.workPlace, ZSTD_BLOCKSIZE_MAX, src, srcSize); + if (ZSTD_isError(cSize)) { DISPLAYLEVEL(1, "warning : could not compress sample size %u \n", (U32)srcSize); return; } - /* literals stats */ - { const BYTE* bytePtr; - for(bytePtr = seqStorePtr->litStart; bytePtr < seqStorePtr->lit; bytePtr++) - countLit[*bytePtr]++; - } - - /* seqStats */ - { size_t const nbSeq = (size_t)(seqStorePtr->offset - seqStorePtr->offsetStart); - ZSTD_seqToCodes(seqStorePtr, nbSeq); + if (cSize) { /* if == 0; block is not compressible */ + const seqStore_t* seqStorePtr = ZSTD_getSeqStore(esr.zc); - { const BYTE* codePtr = seqStorePtr->offCodeStart; - size_t u; - for (u=0; ulitStart; bytePtr < seqStorePtr->lit; bytePtr++) + countLit[*bytePtr]++; } - { const BYTE* codePtr = seqStorePtr->mlCodeStart; - size_t u; - for (u=0; uoffset - seqStorePtr->offsetStart); + ZSTD_seqToCodes(seqStorePtr, nbSeq); - { const BYTE* codePtr = seqStorePtr->llCodeStart; - size_t u; - for (u=0; uoffCodeStart; + size_t u; + for (u=0; uoffsetStart; - U32 offset1 = offsetPtr[0] - 3; - U32 offset2 = offsetPtr[1] - 3; - if (offset1 >= MAXREPOFFSET) offset1 = 0; - if (offset2 >= MAXREPOFFSET) offset2 = 0; - repOffsets[offset1] += 3; - repOffsets[offset2] += 1; - } + { const BYTE* codePtr = seqStorePtr->mlCodeStart; + size_t u; + for (u=0; ullCodeStart; + size_t u; + for (u=0; uoffsetStart; + U32 offset1 = offsetPtr[0] - 3; + U32 offset2 = offsetPtr[1] - 3; + if (offset1 >= MAXREPOFFSET) offset1 = 0; + if (offset2 >= MAXREPOFFSET) offset2 = 0; + repOffsets[offset1] += 3; + repOffsets[offset2] += 1; + } + } } /*