Branch Coverage

lz4frame.c
Criterion Covered Total %
branch 135 366 36.8


line true false branch
210 0 0 if (LZ4F_isError(code)) return LZ4F_errorStrings[-(int)(code)];
216 0 0 if (!LZ4F_isError(functionResult)) return LZ4F_OK_NoError;
241 3 9 if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
243 0 12 if (blockSizeID > 3) return err0r(LZ4F_ERROR_maxBlockSize_invalid);
262 0 1 while (requestedBSID > proposedBSID) {
263 0 0 if (srcSize <= maxBlockSize)
284 0 3 { const LZ4F_preferences_t* const prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr;
293 3 0 size_t const lastBlockSize = flush ? partialBlockSize : 0;
310 2 0 if (preferencesPtr!=NULL) prefs = *preferencesPtr;
344 1 0 if (preferencesPtr!=NULL)
348 1 0 if (prefs.frameInfo.contentSize != 0)
353 0 1 if (srcSize <= LZ4F_getBlockSize(prefs.frameInfo.blockSizeID))
356 1 0 if (prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
364 0 1 if (dstCapacity < LZ4F_compressFrameBound(srcSize, &prefs)) /* condition to guarantee success */
368 0 1 if (LZ4F_isError(headerSize)) return headerSize;
372 0 1 if (LZ4F_isError(cSize)) return cSize;
376 0 1 if (LZ4F_isError(tailSize)) return tailSize;
379 0 1 if (prefs.compressionLevel >= LZ4HC_CLEVEL_MIN) /* Ctx allocation only for lz4hc */
423 0 0 if (!cdict) return NULL;
424 0 0 if (dictSize > 64 KB) {
431 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) {
445 0 0 if (cdict==NULL) return; /* support free on NULL */
468 0 0 if (cctxPtr==NULL) return err0r(LZ4F_ERROR_allocation_failed);
483 0 0 if (cctxPtr != NULL) { /* support free on NULL */
509 0 1 if (dstCapacity < maxFHSize) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
511 0 1 if (preferencesPtr == NULL) preferencesPtr = &prefNull;
515 1 0 { U32 const ctxTypeID = (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) ? 1 : 2; /* 0:nothing ; 1:LZ4 table ; 2:HC tables */
516 0 1 if (cctxPtr->lz4CtxLevel < ctxTypeID) {
518 0 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
522 0 0 if (cctxPtr->lz4CtxPtr == NULL) return err0r(LZ4F_ERROR_allocation_failed);
527 1 0 if (cctxPtr->prefs.frameInfo.blockSizeID == 0)
532 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 */
533 0 0 cctxPtr->maxBlockSize + ((cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 128 KB);
535 0 1 if (cctxPtr->maxBufferSize < requiredBuffSize) {
539 0 0 if (cctxPtr->tmpBuff == NULL) return err0r(LZ4F_ERROR_allocation_failed);
548 1 0 if (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) {
550 0 1 if (cdict) {
551 0 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN) {
558 1 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
571 1 0 *dstPtr++ = (BYTE)(((1 & _2BITS) << 6) /* Version('01') */
580 1 0 if (cctxPtr->prefs.frameInfo.contentSize) {
586 0 1 if (cctxPtr->prefs.frameInfo.dictID) {
641 0 13 if (cSize == 0) { /* compression failed */
646 0 13 if (crcFlag) {
656 0 0 int const acceleration = (level < -1) ? -level : 1;
657 0 0 if (cdict) {
666 0 13 int const acceleration = (level < -1) ? -level : 1;
673 0 0 if (cdict) {
689 1 0 if (level < LZ4HC_CLEVEL_MIN) {
690 0 1 if (blockMode == LZ4F_blockIndependent) return LZ4F_compressBlock;
693 0 0 if (blockMode == LZ4F_blockIndependent) return LZ4F_compressBlockHC;
699 0 0 if (cctxPtr->prefs.compressionLevel < LZ4HC_CLEVEL_MIN)
728 0 1 if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
729 0 1 if (dstCapacity < LZ4F_compressBound_internal(srcSize, &(cctxPtr->prefs), cctxPtr->tmpInSize)) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall);
731 0 1 if (compressOptionsPtr == NULL) compressOptionsPtr = &cOptionsNull;
734 0 1 if (cctxPtr->tmpInSize > 0) { /* some data already within tmp buffer */
736 0 0 if (sizeToCopy > srcSize) {
752 0 0 if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += blockSize;
757 12 1 while ((size_t)(srcEnd - srcPtr) >= blockSize) {
766 1 0 if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd)) {
1 0 if ((cctxPtr->prefs.autoFlush) && (srcPtr < srcEnd)) {
776 1 0 if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)) {
1 0 if ((cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) && (lastBlockCompressed==fromSrcBuffer)) {
777 1 0 if (compressOptionsPtr->stableSrc) {
781 0 0 if (realDictSize==0) return err0r(LZ4F_ERROR_GENERIC);
787 0 1 if ((cctxPtr->tmpIn + blockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize) /* necessarily LZ4F_blockLinked && lastBlockCompressed==fromTmpBuffer */
788 0 0 && !(cctxPtr->prefs.autoFlush))
795 0 1 if (srcPtr < srcEnd) {
802 0 1 if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled)
824 1 0 if (cctxPtr->tmpInSize == 0) return 0; /* nothing to flush */
825 0 0 if (cctxPtr->cStage != 1) return err0r(LZ4F_ERROR_GENERIC);
826 0 0 if (dstCapacity < (cctxPtr->tmpInSize + 4)) return err0r(LZ4F_ERROR_dstMaxSize_tooSmall); /* +4 : block header(4) */
836 0 0 if (cctxPtr->prefs.frameInfo.blockMode==LZ4F_blockLinked) cctxPtr->tmpIn += cctxPtr->tmpInSize;
840 0 0 if ((cctxPtr->tmpIn + cctxPtr->maxBlockSize) > (cctxPtr->tmpBuff + cctxPtr->maxBufferSize)) { /* necessarily LZ4F_blockLinked */
864 0 1 if (LZ4F_isError(flushSize)) return flushSize;
870 0 1 if (cctxPtr->prefs.frameInfo.contentChecksumFlag == LZ4F_contentChecksumEnabled) {
879 1 0 if (cctxPtr->prefs.frameInfo.contentSize) {
880 0 1 if (cctxPtr->prefs.frameInfo.contentSize != cctxPtr->totalInSize)
935 0 8 if (dctx==NULL) return err0r(LZ4F_ERROR_GENERIC);
945 8 0 if (dctx != NULL) { /* can accept NULL input, like free() */
972 0 8 if (srcSize < 5) return err0r(LZ4F_ERROR_frameHeader_incomplete);
975 0 8 if ((LZ4F_readLE32(src) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) return 8;
978 1 7 if (LZ4F_readLE32(src) != LZ4F_MAGICNUMBER)
1005 0 7 if (srcSize < minFHSize) return err0r(LZ4F_ERROR_frameHeader_incomplete); /* minimal frame header size */
1009 0 7 if ((LZ4F_readLE32(srcPtr) & 0xFFFFFFF0U) == LZ4F_MAGIC_SKIPPABLE_START) {
1011 0 0 if (src == (void*)(dctx->header)) {
1023 0 7 if (LZ4F_readLE32(srcPtr) != LZ4F_MAGICNUMBER)
1036 0 7 if (((FLG>>1)&_1BIT) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bit */
1037 0 7 if (version != 1) return err0r(LZ4F_ERROR_headerVersion_wrong); /* Version Number, only supported value */
1043 0 7 if (srcSize < frameHeaderSize) {
1045 0 0 if (srcPtr != dctx->header)
1056 0 7 if (((BD>>7)&_1BIT) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bit */
1057 0 7 if (blockSizeID < 4) return err0r(LZ4F_ERROR_maxBlockSize_invalid); /* 4-7 only supported values for the time being */
1058 0 7 if (((BD>>0)&_4BITS) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bits */
1063 0 7 if (HC != srcPtr[frameHeaderSize-1])
1073 4 3 if (contentSizeFlag)
1076 0 7 if (dictIDFlag)
1103 0 8 if (dctx->dStage > dstage_storeFrameHeader) { /* assumption : dstage_* header enum at beginning of range */
1111 0 8 if (dctx->dStage == dstage_storeFrameHeader) {
1118 1 7 if (LZ4F_isError(hSize)) { *srcSizePtr=0; return hSize; }
1119 0 7 if (*srcSizePtr < hSize) {
1125 0 7 if (LZ4F_isError(decodeResult)) {
1141 3 36 if (dctx->dictSize==0)
1144 39 0 if (dctx->dict + dctx->dictSize == dstPtr) { /* dictionary continuity */
1149 0 0 if (dstPtr - dstPtr0 + dstSize >= 64 KB) { /* dstBuffer large enough to become dictionary */
1155 0 0 if ((withinTmp) && (dctx->dict == dctx->tmpOutBuffer)) {
0 0 if ((withinTmp) && (dctx->dict == dctx->tmpOutBuffer)) {
1161 0 0 if (withinTmp) { /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
1165 0 0 if (dctx->tmpOutSize > 64 KB) copySize = 0;
1166 0 0 if (copySize > preserveSize) copySize = preserveSize;
1175 0 0 if (dctx->dict == dctx->tmpOutBuffer) { /* copy dst into tmp to complete dict */
1176 0 0 if (dctx->dictSize + dstSize > dctx->maxBufferSize) { /* tmp buffer not large enough */
1188 0 0 if (preserveSize > dctx->dictSize) preserveSize = dctx->dictSize;
1234 520 0 if (decompressOptionsPtr==NULL) decompressOptionsPtr = &optionsNull;
1240 610 520 while (doAnotherStage) {
1246 0 0 if ((size_t)(srcEnd-srcPtr) >= maxFHSize) { /* enough to decode - shortcut */
1248 0 0 if (LZ4F_isError(hSize)) return hSize;
1253 0 0 if (srcEnd-srcPtr == 0) return minFHSize; /* 0-size input */
1264 0 0 if (dctx->tmpInSize < dctx->tmpInTarget) {
1270 0 0 if (LZ4F_isError(hSize)) return hSize;
1275 1 5 if (dctx->frameInfo.contentChecksumFlag) XXH32_reset(&(dctx->xxh), 0);
1278 3 3 + ((dctx->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB);
1279 6 0 if (bufferNeeded > dctx->maxBufferSize) { /* tmp buffers too small */
1283 0 6 if (dctx->tmpIn == NULL)
1287 0 6 if (dctx->tmpOutBuffer== NULL)
1301 48 0 if ((size_t)(srcEnd - srcPtr) >= BHSize) {
1310 0 48 if (dctx->dStage == dstage_storeBlockHeader) /* can be skipped */
1319 0 0 if (dctx->tmpInSize < BHSize) { /* not enough input for cBlockSize */
1330 5 43 if (nextCBlockSize==0) { /* frameEnd signal, no more block */
1334 0 43 if (nextCBlockSize > dctx->maxBlockSize)
1336 0 43 if (LZ4F_readLE32(selectedIn) & LZ4F_BLOCKUNCOMPRESSED_FLAG) {
1339 0 0 if (dctx->frameInfo.blockChecksumFlag) {
1348 1 42 if (dstPtr==dstEnd) {
1359 0 0 if (dctx->frameInfo.blockChecksumFlag) {
1362 0 0 if (dctx->frameInfo.contentChecksumFlag)
1364 0 0 if (dctx->frameInfo.contentSize)
1368 0 0 if (dctx->frameInfo.blockMode == LZ4F_blockLinked)
1373 0 0 if (sizeToCopy == dctx->tmpInTarget) { /* all done */
1374 0 0 if (dctx->frameInfo.blockChecksumFlag) {
1392 0 0 if ((srcEnd-srcPtr >= 4) && (dctx->tmpInSize==0)) {
0 0 if ((srcEnd-srcPtr >= 4) && (dctx->tmpInSize==0)) {
1401 0 0 if (dctx->tmpInSize < 4) { /* all input consumed */
1409 0 0 if (readCRC != calcCRC)
1417 1 42 if ((size_t)(srcEnd-srcPtr) < dctx->tmpInTarget) {
1434 1 0 if (dctx->tmpInSize < dctx->tmpInTarget) { /* need more input */
1443 0 42 if (dctx->frameInfo.blockChecksumFlag) {
1448 0 0 if (readBlockCrc != calcBlockCrc)
1452 37 5 if ((size_t)(dstEnd-dstPtr) >= dctx->maxBlockSize) {
1458 0 37 if (decodedSize < 0) return err0r(LZ4F_ERROR_GENERIC); /* decompression failed */
1459 0 37 if (dctx->frameInfo.contentChecksumFlag)
1461 36 1 if (dctx->frameInfo.contentSize)
1465 36 1 if (dctx->frameInfo.blockMode==LZ4F_blockLinked)
1475 3 2 if (dctx->frameInfo.blockMode == LZ4F_blockLinked) {
1476 0 3 if (dctx->dict == dctx->tmpOutBuffer) {
1477 0 0 if (dctx->dictSize > 128 KB) {
1493 0 5 if (decodedSize < 0) /* decompression failed */
1495 1 4 if (dctx->frameInfo.contentChecksumFlag)
1497 3 2 if (dctx->frameInfo.contentSize)
1510 3 515 if (dctx->frameInfo.blockMode==LZ4F_blockLinked)
1516 5 513 if (dctx->tmpOutStart == dctx->tmpOutSize) { /* all flushed */
1526 0 5 if (dctx->frameRemainingSize)
1528 4 1 if (!dctx->frameInfo.contentChecksumFlag) { /* no checksum, frame is completed */
1534 0 1 if ((srcEnd - srcPtr) < 4) { /* not enough size for entire CRC */
1542 0 1 if (dctx->dStage == dstage_storeSuffix) /* can be skipped */
1550 0 0 if (dctx->tmpInSize < 4) { /* not enough input to read complete suffix */
1561 0 1 if (readCRC != resultCRC)
1570 0 0 if ((srcEnd - srcPtr) >= 4) {
1580 0 0 if (dctx->dStage == dstage_storeSFrameSize)
1588 0 0 if (dctx->tmpInSize < dctx->tmpInTarget) {
1611 0 0 if (nextSrcSizeHint) break; /* still more to skip */
1621 3 517 if ( (dctx->frameInfo.blockMode==LZ4F_blockLinked) /* next block will use up to 64KB from previous ones */
1622 3 0 && (dctx->dict != dctx->tmpOutBuffer) /* dictionary is not already within tmp */
1623 3 0 && (!decompressOptionsPtr->stableDst) /* cannot rely on dst data to remain there for next call */
1624 0 3 && ((unsigned)(dctx->dStage)-2 < (unsigned)(dstage_getSuffix)-2) ) /* valid stages : [init ... getSuffix[ */
1626 0 0 if (dctx->dStage == dstage_flushOut) {
1630 0 0 if (dctx->tmpOutSize > 64 KB) copySize = 0;
1631 0 0 if (copySize > preserveSize) copySize = preserveSize;
1633 0 0 if (copySize > 0)
1642 0 0 if (newDictSize > 0)
1667 0 0 if (dctx->dStage <= dstage_init) {