fix minor visual static analyzer warning

it's a false positive,
but change the code nonetheless to make it more obvious to the static analyzer.
This commit is contained in:
Yann Collet
2024-02-25 19:45:32 -08:00
parent 038a8a906b
commit 1fafd0c4ae
+9 -15
View File
@@ -500,16 +500,12 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
size_t const targetCBlockSize = MAX(minTarget, cctxParams->targetCBlockSize); size_t const targetCBlockSize = MAX(minTarget, cctxParams->targetCBlockSize);
int writeLitEntropy = (entropyMetadata->hufMetadata.hType == set_compressed); int writeLitEntropy = (entropyMetadata->hufMetadata.hType == set_compressed);
int writeSeqEntropy = 1; int writeSeqEntropy = 1;
size_t nbSubBlocks = 1;
size_t avgLitCost, avgSeqCost, avgBlockBudget;
DEBUGLOG(5, "ZSTD_compressSubBlock_multi (srcSize=%u, litSize=%u, nbSeq=%u)", DEBUGLOG(5, "ZSTD_compressSubBlock_multi (srcSize=%u, litSize=%u, nbSeq=%u)",
(unsigned)srcSize, (unsigned)(lend-lstart), (unsigned)(send-sstart)); (unsigned)srcSize, (unsigned)(lend-lstart), (unsigned)(send-sstart));
/* let's start by a general estimation for the full block */ /* let's start by a general estimation for the full block */
if (nbSeqs == 0) { if (nbSeqs > 0) {
nbSubBlocks = 1;
} else {
EstimatedBlockSize const ebs = EstimatedBlockSize const ebs =
ZSTD_estimateSubBlockSize(lp, nbLiterals, ZSTD_estimateSubBlockSize(lp, nbLiterals,
ofCodePtr, llCodePtr, mlCodePtr, nbSeqs, ofCodePtr, llCodePtr, mlCodePtr, nbSeqs,
@@ -517,19 +513,17 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
workspace, wkspSize, workspace, wkspSize,
writeLitEntropy, writeSeqEntropy); writeLitEntropy, writeSeqEntropy);
/* quick estimation */ /* quick estimation */
avgLitCost = nbLiterals ? (ebs.estLitSize * BYTESCALE) / nbLiterals : BYTESCALE; size_t const avgLitCost = nbLiterals ? (ebs.estLitSize * BYTESCALE) / nbLiterals : BYTESCALE;
avgSeqCost = ((ebs.estBlockSize - ebs.estLitSize) * BYTESCALE) / nbSeqs; size_t const avgSeqCost = ((ebs.estBlockSize - ebs.estLitSize) * BYTESCALE) / nbSeqs;
nbSubBlocks = (ebs.estBlockSize + (targetCBlockSize-1)) / targetCBlockSize; size_t nbSubBlocks = (ebs.estBlockSize + (targetCBlockSize-1)) / targetCBlockSize;
size_t n, avgBlockBudget, blockBudgetSupp=0;
if (nbSubBlocks<1) nbSubBlocks=1; if (nbSubBlocks<1) nbSubBlocks=1;
avgBlockBudget = (ebs.estBlockSize * BYTESCALE) / nbSubBlocks; avgBlockBudget = (ebs.estBlockSize * BYTESCALE) / nbSubBlocks;
DEBUGLOG(5, "estimated fullblock size=%u bytes ; avgLitCost=%.2f ; avgSeqCost=%.2f ; targetCBlockSize=%u, nbSubBlocks=%u ; avgBlockBudget=%.0f bytes", DEBUGLOG(5, "estimated fullblock size=%u bytes ; avgLitCost=%.2f ; avgSeqCost=%.2f ; targetCBlockSize=%u, nbSubBlocks=%u ; avgBlockBudget=%.0f bytes",
(unsigned)ebs.estBlockSize, (double)avgLitCost/BYTESCALE, (double)avgSeqCost/BYTESCALE, (unsigned)ebs.estBlockSize, (double)avgLitCost/BYTESCALE, (double)avgSeqCost/BYTESCALE,
(unsigned)targetCBlockSize, (unsigned)nbSubBlocks, (double)avgBlockBudget/BYTESCALE); (unsigned)targetCBlockSize, (unsigned)nbSubBlocks, (double)avgBlockBudget/BYTESCALE);
}
/* compress and write sub-blocks */ /* compress and write sub-blocks */
{ size_t n;
size_t blockBudgetSupp = 0;
for (n=0; n+1 < nbSubBlocks; n++) { for (n=0; n+1 < nbSubBlocks; n++) {
/* determine nb of sequences for current sub-block + nbLiterals from next sequence */ /* determine nb of sequences for current sub-block + nbLiterals from next sequence */
size_t seqCount = sizeBlockSequences(sp, (size_t)(send-sp), avgBlockBudget + blockBudgetSupp, avgLitCost, avgSeqCost, n==0); size_t seqCount = sizeBlockSequences(sp, (size_t)(send-sp), avgBlockBudget + blockBudgetSupp, avgLitCost, avgSeqCost, n==0);
@@ -577,6 +571,7 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
} } } }
/* otherwise : do not compress yet, coalesce current block with next one */ /* otherwise : do not compress yet, coalesce current block with next one */
} }
} /* if (nbSeqs > 0) */
/* write last block */ /* write last block */
DEBUGLOG(2, "Generate last sub-block: %u sequences remaining", (unsigned)(send - sp)); DEBUGLOG(2, "Generate last sub-block: %u sequences remaining", (unsigned)(send - sp));
@@ -616,11 +611,10 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
writeSeqEntropy = 0; writeSeqEntropy = 0;
} }
sp += seqCount; sp += seqCount;
blockBudgetSupp = 0;
}
} }
} }
if (writeLitEntropy) { if (writeLitEntropy) {
DEBUGLOG(5, "Literal entropy tables were never written"); DEBUGLOG(5, "Literal entropy tables were never written");
ZSTD_memcpy(&nextCBlock->entropy.huf, &prevCBlock->entropy.huf, sizeof(prevCBlock->entropy.huf)); ZSTD_memcpy(&nextCBlock->entropy.huf, &prevCBlock->entropy.huf, sizeof(prevCBlock->entropy.huf));
@@ -653,8 +647,8 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
} }
} }
DEBUGLOG(5, "ZSTD_compressSubBlock_multi compressed %u subBlocks: total compressed size = %u", DEBUGLOG(5, "ZSTD_compressSubBlock_multi compressed all subBlocks: total compressed size = %u",
(unsigned)nbSubBlocks, (unsigned)(op-ostart)); (unsigned)(op-ostart));
return (size_t)(op-ostart); return (size_t)(op-ostart);
} }