Branch Coverage

lz4frame.c
Criterion Covered Total %
branch 134 370 36.2


line true false branch
202 0 0 if (LZ4F_isError(code)) return LZ4F_errorStrings[-(int)(code)];
208 0 0 if (!LZ4F_isError(functionResult)) return LZ4F_OK_NoError;
233 3 9 if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
235 0 12 if (blockSizeID > 3) return err0r(LZ4F_ERROR_maxBlockSize_invalid);
254 0 1 while (requestedBSID > proposedBSID) {
255 0 0 if (srcSize <= maxBlockSize)
276 0 3 { const LZ4F_preferences_t* const prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr;
285 3 0 size_t const lastBlockSize = flush ? partialBlockSize : 0;
302 2 0 if (preferencesPtr!=NULL) prefs = *preferencesPtr;
336 1 0 if (preferencesPtr!=NULL)
340 1 0 if (prefs.frameInfo.contentSize != 0)
345 0 1 if (srcSize <= LZ4F_getBlockSize(prefs.frameInfo.blockSizeID))
348 1 0 if (prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
356 0 1 if (dstCapacity < LZ4F_compressFrameBound(srcSize, &prefs)) /* condition to guarantee success */
360 0 1 if (LZ4F_isError(headerSize)) return headerSize;
364 0 1 if (LZ4F_isError(cSize)) return cSize;
368 0 1 if (LZ4F_isError(tailSize)) return tailSize;
371 0 1 if (prefs.compressionLevel >= LZ4HC_CLEVEL_MIN) /* Ctx allocation only for lz4hc */
415 0 0 if (!cdict) return NULL;
416 0 0 if (dictSize > 64 KB) {
423 0 0 if (!cdict->dictContent || !cdict->fastCtx || !cdict->HCCtx) {
0 0 if (!cdict->dictContent || !cdict->fastCtx || !cdict->HCCtx) {
0 0 if (!cdict->dictContent || !cdict->fastCtx || !cdict->HCCtx) {
437 0 0 if (cdict==NULL) return; /* support free on NULL */
460 0 0 if (cctxPtr==NULL) return err0r(LZ4F_ERROR_allocation_failed);
475 0 0 if (cctxPtr != NULL) { /* support free on NULL */
501 0 1 if (dstCapacity < maxFHSize) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
503 0 1 if (preferencesPtr == NULL) preferencesPtr = &prefNull;
507 1 0 { U32 const tableID = (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) ? 1 : 2; /* 0:nothing ; 1:LZ4 table ; 2:HC tables */
508 0 1 if (cctxPtr->lz4CtxLevel < tableID) {
510 0 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
514 0 0 if (cctxPtr->lz4CtxPtr == NULL) return err0r(LZ4F_ERROR_allocation_failed);
519 1 0 if (cctxPtr->prefs.frameInfo.blockSizeID == 0)
524 1 0 (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 64 KB : /* only needs windows size */
1 0 (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 64 KB : /* only needs windows size */
525 0 0 cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 128 KB);
527 0 1 if (cctxPtr->maxBufferSize < requiredBuffSize) {
531 0 0 if (cctxPtr->tmpBuff == NULL) return err0r(LZ4F_ERROR_allocation_failed);
540 1 0 if (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) {
542 0 1 if (cdict) {
543 0 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
550 1 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
563 1 0 *dstPtr++ = (BYTE)(((1 & _2BITS) << 6) /* Version('01') */
572 1 0 if (cctxPtr->prefs.frameInfo.contentSize) {
578 0 1 if (cctxPtr->prefs.frameInfo.dictID) {
633 0 13 if (cSize == 0) { /* compression failed */
638 0 13 if (crcFlag) {
648 0 0 int const acceleration = (level < -1) ? -level : 1;
649 0 0 if (cdict) {
658 0 13 int const acceleration = (level < -1) ? -level : 1;
665 0 0 if (cdict) {
681 1 0 if (level < LZ4HC_CLEVEL_MIN) {
682 0 1 if (blockMode == LZ4F_blockIndependent) return LZ4F_compressBlock;
685 0 0 if (blockMode == LZ4F_blockIndependent) return LZ4F_compressBlockHC;
691 0 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
720 0 1 if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
721 0 1 if (dstCapacity < LZ4F_compressBound_internal(srcSize, &(cctxPtr->prefs), cctxPtr->tmpInSize)) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
723 0 1 if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
726 0 1 if (cctxPtr->tmpInSize > 0) { /* some data already within tmp buffer */
728 0 0 if (sizeToCopy > srcSize) {
744 0 0 if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += blockSize;
749 12 1 while ((size_t)(srcEnd - srcPtr) >= blockSize) {
758 1 0 if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd)) {
1 0 if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd)) {
768 1 0 if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)) {
1 0 if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)) {
769 1 0 if (compressOptionsPtr->stableSrc) {
773 0 0 if (realDictSize==0) return err0r(LZ4F_ERROR_GENERIC);
779 0 1 if ((cctxPtr->tmpIn + blockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize) /* necessarily LZ4F_blockLinked && lastBlockCompressed==fromTmpBuffer */
780 0 0 && !(cctxPtr->prefs.autoFlush))
787 0 1 if (srcPtr < srcEnd) {
794 0 1 if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled)
816 1 0 if (cctxPtr->tmpInSize == 0) return 0; /* nothing to flush */
817 0 0 if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
818 0 0 if (dstCapacity < (cctxPtr->tmpInSize + 4)) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall); /* +4 : block header(4) */
828 0 0 if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += cctxPtr->tmpInSize;
832 0 0 if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize)) { /* necessarily LZ4F_blockLinked */
856 0 1 if (LZ4F_isError(flushSize)) return flushSize;
862 0 1 if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled) {
871 1 0 if (cctxPtr->prefs.frameInfo.contentSize) {
872 0 1 if (cctxPtr->prefs.frameInfo.contentSize != cctxPtr->totalInSize)
928 0 8 if (dctx==NULL) return err0r(LZ4F_ERROR_GENERIC);
938 6 0 if (dctx != NULL) { /* can accept NULL input, like free() */
965 0 8 if (srcSize < 5) return err0r(LZ4F_ERROR_frameHeader_incomplete);
968 0 8 if ((LZ4F_readLE32(src) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) return 8;
971 1 7 if (LZ4F_readLE32(src) != LZ4F_MAGICNUMBER)
998 0 7 if (srcSize < minFHSize) return err0r(LZ4F_ERROR_frameHeader_incomplete); /* minimal frame header size */
1002 0 7 if ((LZ4F_readLE32(srcPtr) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) {
1004 0 0 if (src == (void*)(dctx->header)) {
1016 0 7 if (LZ4F_readLE32(srcPtr) != LZ4F_MAGICNUMBER)
1029 0 7 if (((FLG>>1)&_1BIT) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bit */
1030 0 7 if (version != 1) return err0r(LZ4F_ERROR_headerVersion_wrong); /* Version Number, only supported value */
1036 0 7 if (srcSize < frameHeaderSize) {
1038 0 0 if (srcPtr != dctx->header)
1049 0 7 if (((BD>>7)&_1BIT) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bit */
1050 0 7 if (blockSizeID < 4) return err0r(LZ4F_ERROR_maxBlockSize_invalid); /* 4-7 only supported values for the time being */
1051 0 7 if (((BD>>0)&_4BITS) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bits */
1056 0 7 if (HC != srcPtr[frameHeaderSize-1])
1066 4 3 if (contentSizeFlag)
1069 0 7 if (dictIDFlag)
1096 0 8 if (dctx->dStage > dstage_storeFrameHeader) { /* assumption : dstage_* header enum at beginning of range */
1104 0 8 if (dctx->dStage == dstage_storeFrameHeader) {
1111 1 7 if (LZ4F_isError(hSize)) { *srcSizePtr=0; return hSize; }
1112 0 7 if (*srcSizePtr < hSize) {
1118 0 7 if (LZ4F_isError(decodeResult)) {
1134 3 36 if (dctx->dictSize==0)
1137 39 0 if (dctx->dict + dctx->dictSize == dstPtr) { /* dictionary continuity */
1142 0 0 if (dstPtr - dstPtr0 + dstSize >= 64 KB) { /* dstBuffer large enough to become dictionary */
1148 0 0 if ((withinTmp) && (dctx->dict == dctx->tmpOutBuffer)) {
0 0 if ((withinTmp) && (dctx->dict == dctx->tmpOutBuffer)) {
1154 0 0 if (withinTmp) { /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
1158 0 0 if (dctx->tmpOutSize > 64 KB) copySize = 0;
1159 0 0 if (copySize > preserveSize) copySize = preserveSize;
1168 0 0 if (dctx->dict == dctx->tmpOutBuffer) { /* copy dst into tmp to complete dict */
1169 0 0 if (dctx->dictSize + dstSize > dctx->maxBufferSize) { /* tmp buffer not large enough */
1181 0 0 if (preserveSize > dctx->dictSize) preserveSize = dctx->dictSize;
1227 520 0 if (decompressOptionsPtr==NULL) decompressOptionsPtr = &optionsNull;
1233 694 520 while (doAnotherStage) {
1239 0 0 if ((size_t)(srcEnd-srcPtr) >= maxFHSize) { /* enough to decode - shortcut */
1241 0 0 if (LZ4F_isError(hSize)) return hSize;
1246 0 0 if (srcEnd-srcPtr == 0) return minFHSize; /* 0-size input */
1256 0 0 if (dctx->tmpInSize < dctx->tmpInTarget) {
1262 0 0 if (LZ4F_isError(hSize)) return hSize;
1268 1 5 if (dctx->frameInfo.contentChecksumFlag) XXH32_reset(&(dctx->xxh), 0);
1270 3 3 { size_t const bufferNeeded = dctx->maxBlockSize + ((dctx->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB) + 4 /* block checksum */;
1271 6 0 if (bufferNeeded > dctx->maxBufferSize) { /* tmp buffers too small */
1275 0 6 if (dctx->tmpIn == NULL) return err0r(LZ4F_ERROR_allocation_failed);
1278 0 6 if (dctx->tmpOutBuffer== NULL) return err0r(LZ4F_ERROR_allocation_failed);
1291 48 0 if ((size_t)(srcEnd - srcPtr) >= BHSize) {
1300 0 48 if (dctx->dStage == dstage_storeBlockHeader) /* can be skipped */
1303 0 0 if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
1307 0 0 if (dctx->tmpInSize < BHSize) { /* not enough input for cBlockSize */
1318 5 43 if (nextCBlockSize==0) { /* frameEnd signal, no more block */
1322 0 43 if (nextCBlockSize > dctx->maxBlockSize)
1324 0 43 if (LZ4F_readLE32(selectedIn) & LZ4F_BLOCKUNCOMPRESSED_FLAG) {
1327 0 0 if (dctx->frameInfo.blockChecksumFlag) {
1336 1 42 if (dstPtr==dstEnd) {
1347 0 0 if (dctx->frameInfo.blockChecksumFlag) {
1350 0 0 if (dctx->frameInfo.contentChecksumFlag)
1352 0 0 if (dctx->frameInfo.contentSize)
1356 0 0 if (dctx->frameInfo.blockMode == LZ4F_blockLinked)
1361 0 0 if (sizeToCopy == dctx->tmpInTarget) { /* all done */
1362 0 0 if (dctx->frameInfo.blockChecksumFlag) {
1380 0 0 if ((srcEnd-srcPtr >= 4) && (dctx->tmpInSize==0)) {
0 0 if ((srcEnd-srcPtr >= 4) && (dctx->tmpInSize==0)) {
1389 0 0 if (dctx->tmpInSize < 4) { /* all input consumed */
1397 0 0 if (readCRC != calcCRC)
1405 1 42 if ((size_t)(srcEnd-srcPtr) < dctx->tmpInTarget) {
1421 1 0 if (dctx->tmpInSize < dctx->tmpInTarget) { /* need more input */
1433 0 42 if (dctx->frameInfo.blockChecksumFlag) {
1437 0 0 if (readBlockCrc != calcBlockCrc)
1440 5 37 if ((size_t)(dstEnd-dstPtr) < dctx->maxBlockSize) /* not enough place into dst : decode into tmpOut */
1451 0 37 if (decodedSize < 0) return err0r(LZ4F_ERROR_GENERIC); /* decompression failed */
1452 0 37 if (dctx->frameInfo.contentChecksumFlag)
1454 36 1 if (dctx->frameInfo.contentSize)
1458 36 1 if (dctx->frameInfo.blockMode==LZ4F_blockLinked)
1470 3 2 if (dctx->frameInfo.blockMode == LZ4F_blockLinked) {
1471 0 3 if (dctx->dict == dctx->tmpOutBuffer) {
1472 0 0 if (dctx->dictSize > 128 KB) {
1488 0 5 if (decodedSize < 0) /* decompression failed */
1490 1 4 if (dctx->frameInfo.contentChecksumFlag)
1492 3 2 if (dctx->frameInfo.contentSize)
1505 3 515 if (dctx->frameInfo.blockMode==LZ4F_blockLinked)
1511 5 513 if (dctx->tmpOutStart == dctx->tmpOutSize) { /* all flushed */
1522 0 5 if (dctx->frameRemainingSize)
1524 4 1 if (suffixSize == 0) { /* frame completed */
1530 0 1 if ((srcEnd - srcPtr) < 4) { /* not enough size for entire CRC */
1539 0 1 if (dctx->dStage == dstage_storeSuffix) /* can be skipped */
1543 0 0 if (sizeToCopy > (size_t)(srcEnd - srcPtr)) sizeToCopy = srcEnd - srcPtr;
1547 0 0 if (dctx->tmpInSize < 4) { /* not enough input to read complete suffix */
1558 0 1 if (readCRC != resultCRC)
1567 0 0 if ((srcEnd - srcPtr) >= 4) {
1577 0 0 if (dctx->dStage == dstage_storeSFrameSize)
1585 0 0 if (dctx->tmpInSize < dctx->tmpInTarget) {
1608 0 0 if (nextSrcSizeHint) break; /* still more to skip */
1616 3 517 if ( (dctx->frameInfo.blockMode==LZ4F_blockLinked)
1617 3 0 && (dctx->dict != dctx->tmpOutBuffer)
1618 0 3 && (dctx->dStage != dstage_getFrameHeader)
1619 0 0 && (!decompressOptionsPtr->stableDst)
1620 0 0 && ((unsigned)(dctx->dStage-1) < (unsigned)(dstage_getSuffix-1)) )
1622 0 0 if (dctx->dStage == dstage_flushOut) {
1626 0 0 if (dctx->tmpOutSize > 64 KB) copySize = 0;
1627 0 0 if (copySize > preserveSize) copySize = preserveSize;
1636 0 0 if ((newDictSize) > 64 KB) newDictSize = 64 KB;
1662 0 0 if (dctx->dStage <= dstage_init) {