Branch Coverage

decompress.c
Criterion Covered Total %
branch 363 502 72.3


line true false branch
31 7424 29 for (i = 0; i < 256; i++)
32 1400 6024 if (s->inUse[i]) {
140 29 51099 if (s->state == BZ_X_MAGIC_1) {
198 29 29 GET_UCHAR(BZ_X_MAGIC_1, uc);
0 29 GET_UCHAR(BZ_X_MAGIC_1, uc);
0 29 GET_UCHAR(BZ_X_MAGIC_1, uc);
199 0 29 if (uc != BZ_HDR_B) RETURN(BZ_DATA_ERROR_MAGIC);
201 29 39 GET_UCHAR(BZ_X_MAGIC_2, uc);
10 29 GET_UCHAR(BZ_X_MAGIC_2, uc);
0 29 GET_UCHAR(BZ_X_MAGIC_2, uc);
202 0 29 if (uc != BZ_HDR_Z) RETURN(BZ_DATA_ERROR_MAGIC);
204 29 41 GET_UCHAR(BZ_X_MAGIC_3, uc)
12 29 GET_UCHAR(BZ_X_MAGIC_3, uc)
0 29 GET_UCHAR(BZ_X_MAGIC_3, uc)
205 0 29 if (uc != BZ_HDR_h) RETURN(BZ_DATA_ERROR_MAGIC);
207 29 39 GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
10 29 GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
0 29 GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
208 29 0 if (s->blockSize100k < (BZ_HDR_0 + 1) ||
0 29 if (s->blockSize100k < (BZ_HDR_0 + 1) ||
212 0 29 if (s->smallDecompress) {
217 0 0 if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
0 0 if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
220 0 29 if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
223 58 78 GET_UCHAR(BZ_X_BLKHDR_1, uc);
20 58 GET_UCHAR(BZ_X_BLKHDR_1, uc);
0 58 GET_UCHAR(BZ_X_BLKHDR_1, uc);
225 29 29 if (uc == 0x17) goto endhdr_2;
226 0 29 if (uc != 0x31) RETURN(BZ_DATA_ERROR);
227 29 39 GET_UCHAR(BZ_X_BLKHDR_2, uc);
10 29 GET_UCHAR(BZ_X_BLKHDR_2, uc);
0 29 GET_UCHAR(BZ_X_BLKHDR_2, uc);
228 0 29 if (uc != 0x41) RETURN(BZ_DATA_ERROR);
229 29 39 GET_UCHAR(BZ_X_BLKHDR_3, uc);
10 29 GET_UCHAR(BZ_X_BLKHDR_3, uc);
0 29 GET_UCHAR(BZ_X_BLKHDR_3, uc);
230 0 29 if (uc != 0x59) RETURN(BZ_DATA_ERROR);
231 29 39 GET_UCHAR(BZ_X_BLKHDR_4, uc);
10 29 GET_UCHAR(BZ_X_BLKHDR_4, uc);
0 29 GET_UCHAR(BZ_X_BLKHDR_4, uc);
232 0 29 if (uc != 0x26) RETURN(BZ_DATA_ERROR);
233 29 39 GET_UCHAR(BZ_X_BLKHDR_5, uc);
10 29 GET_UCHAR(BZ_X_BLKHDR_5, uc);
0 29 GET_UCHAR(BZ_X_BLKHDR_5, uc);
234 0 29 if (uc != 0x53) RETURN(BZ_DATA_ERROR);
235 29 39 GET_UCHAR(BZ_X_BLKHDR_6, uc);
10 29 GET_UCHAR(BZ_X_BLKHDR_6, uc);
0 29 GET_UCHAR(BZ_X_BLKHDR_6, uc);
236 0 29 if (uc != 0x59) RETURN(BZ_DATA_ERROR);
243 29 39 GET_UCHAR(BZ_X_BCRC_1, uc);
10 29 GET_UCHAR(BZ_X_BCRC_1, uc);
0 29 GET_UCHAR(BZ_X_BCRC_1, uc);
245 29 39 GET_UCHAR(BZ_X_BCRC_2, uc);
10 29 GET_UCHAR(BZ_X_BCRC_2, uc);
0 29 GET_UCHAR(BZ_X_BCRC_2, uc);
247 29 39 GET_UCHAR(BZ_X_BCRC_3, uc);
10 29 GET_UCHAR(BZ_X_BCRC_3, uc);
0 29 GET_UCHAR(BZ_X_BCRC_3, uc);
249 29 39 GET_UCHAR(BZ_X_BCRC_4, uc);
10 29 GET_UCHAR(BZ_X_BCRC_4, uc);
0 29 GET_UCHAR(BZ_X_BCRC_4, uc);
252 29 39 GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
10 29 GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
0 29 GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
255 29 39 GET_UCHAR(BZ_X_ORIGPTR_1, uc);
10 29 GET_UCHAR(BZ_X_ORIGPTR_1, uc);
0 29 GET_UCHAR(BZ_X_ORIGPTR_1, uc);
257 29 39 GET_UCHAR(BZ_X_ORIGPTR_2, uc);
10 29 GET_UCHAR(BZ_X_ORIGPTR_2, uc);
0 29 GET_UCHAR(BZ_X_ORIGPTR_2, uc);
259 29 39 GET_UCHAR(BZ_X_ORIGPTR_3, uc);
10 29 GET_UCHAR(BZ_X_ORIGPTR_3, uc);
0 29 GET_UCHAR(BZ_X_ORIGPTR_3, uc);
262 0 29 if (s->origPtr < 0)
264 0 29 if (s->origPtr > 10 + 100000*s->blockSize100k)
268 464 29 for (i = 0; i < 16; i++) {
269 464 78 GET_BIT(BZ_X_MAPPING_1, uc);
20 58 GET_BIT(BZ_X_MAPPING_1, uc);
0 58 GET_BIT(BZ_X_MAPPING_1, uc);
270 180 284 if (uc == 1)
275 7424 29 for (i = 0; i < 256; i++) s->inUse[i] = False;
277 464 29 for (i = 0; i < 16; i++)
278 180 284 if (s->inUse16[i])
279 2880 180 for (j = 0; j < 16; j++) {
280 2880 474 GET_BIT(BZ_X_MAPPING_2, uc);
114 360 GET_BIT(BZ_X_MAPPING_2, uc);
0 360 GET_BIT(BZ_X_MAPPING_2, uc);
281 1400 1480 if (uc == 1) s->inUse[i * 16 + j] = True;
284 0 29 if (s->nInUse == 0) RETURN(BZ_DATA_ERROR);
288 29 0 GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
0 0 GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
0 0 GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
289 29 0 if (nGroups < 2 || nGroups > BZ_N_GROUPS) RETURN(BZ_DATA_ERROR);
0 29 if (nGroups < 2 || nGroups > BZ_N_GROUPS) RETURN(BZ_DATA_ERROR);
290 29 78 GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
20 58 GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
0 58 GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
291 0 29 if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
292 2260 29 for (i = 0; i < nSelectors; i++) {
295 7546 1363 GET_BIT(BZ_X_SELECTOR_3, uc);
421 942 GET_BIT(BZ_X_SELECTOR_3, uc);
0 942 GET_BIT(BZ_X_SELECTOR_3, uc);
296 2260 5286 if (uc == 0) break;
298 0 5286 if (j >= nGroups) RETURN(BZ_DATA_ERROR);
303 2260 0 if (i < BZ_MAX_SELECTORS)
306 0 29 if (nSelectors > BZ_MAX_SELECTORS)
312 81 29 for (v = 0; v < nGroups; v++) pos[v] = v;
314 2260 29 for (i = 0; i < nSelectors; i++) {
317 5286 2260 while (v > 0) { pos[v] = pos[v-1]; v--; }
324 81 29 for (t = 0; t < nGroups; t++) {
325 81 51 GET_BITS(BZ_X_CODING_1, curr, 5);
12 39 GET_BITS(BZ_X_CODING_1, curr, 5);
0 39 GET_BITS(BZ_X_CODING_1, curr, 5);
326 7154 81 for (i = 0; i < alphaSize; i++) {
328 11350 0 if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
0 11350 if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
329 11350 1761 GET_BIT(BZ_X_CODING_2, uc);
334 1427 GET_BIT(BZ_X_CODING_2, uc);
0 1427 GET_BIT(BZ_X_CODING_2, uc);
330 7154 4196 if (uc == 0) break;
331 4196 620 GET_BIT(BZ_X_CODING_3, uc);
94 526 GET_BIT(BZ_X_CODING_3, uc);
0 526 GET_BIT(BZ_X_CODING_3, uc);
332 2145 2051 if (uc == 0) curr++; else curr--;
339 81 29 for (t = 0; t < nGroups; t++) {
342 7154 81 for (i = 0; i < alphaSize; i++) {
343 120 7034 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
344 188 6966 if (s->len[t][i] < minLen) minLen = s->len[t][i];
363 7424 29 for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
369 464 29 for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
370 7424 464 for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
380 29 0 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
0 29 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
29 11 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
1 10 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
0 10 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
0 67 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
29 38 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
38 2 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
0 2 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
0 2 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
29 0 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
0 29 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
384 29 110684 if (nextSym == EOB) break;
386 110260 424 if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
167 110093 if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
397 0 2015 if (N >= 2*1024*1024) RETURN(BZ_DATA_ERROR);
398 1034 981 if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
399 981 0 if (nextSym == BZ_RUNB) es = es + (1+1) * N;
401 36 1979 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 36 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
2015 721 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
167 554 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 554 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 3801 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
2015 1786 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
1786 251 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
17 234 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 234 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
2015 0 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 2015 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
403 610 1405 while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
814 591 while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
409 0 591 if (s->smallDecompress)
410 0 0 while (es > 0) {
411 0 0 if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
417 353470 591 while (es > 0) {
418 0 353470 if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
428 0 110093 if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
436 6917 103176 if (nn < MTFL_SIZE) {
440 11055 6917 while (nn > 3) {
448 11017 6917 while (nn > 0) {
458 765938 103176 while (pp > s->mtfbase[lno]) {
462 822329 103176 while (lno > 0) {
470 26 103150 if (s->mtfbase[0] == 0) {
472 416 26 for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
473 6656 416 for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
485 0 110093 if (s->smallDecompress)
490 2195 107898 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 2195 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110093 139945 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
43885 96060 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 96060 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 216709 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110093 106616 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
106616 18575 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
5713 12862 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 12862 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110093 0 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 110093 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
498 29 0 if (s->origPtr < 0 || s->origPtr >= nblock)
0 29 if (s->origPtr < 0 || s->origPtr >= nblock)
503 7424 29 for (i = 0; i <= 255; i++) {
504 7424 0 if (s->unzftab[i] < 0 || s->unzftab[i] > nblock)
0 7424 if (s->unzftab[i] < 0 || s->unzftab[i] > nblock)
509 7424 29 for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
510 7424 29 for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
512 7453 29 for (i = 0; i <= 256; i++) {
513 7453 0 if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
0 7453 if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
519 7424 29 for (i = 1; i <= 256; i++) {
520 0 7424 if (s->cftab[i-1] > s->cftab[i]) {
531 0 29 if (s->smallDecompress) {
534 0 0 for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
537 0 0 for (i = 0; i < nblock; i++) {
539 0 0 SET_LL(i, s->cftabCopy[uc]);
548 0 0 SET_LL(j, i);
552 0 0 while (i != s->origPtr);
556 0 0 if (s->blockRandomised) {
558 0 0 BZ_GET_SMALL(s->k0); s->nblock_used++;
559 0 0 BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
0 0 BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
561 0 0 BZ_GET_SMALL(s->k0); s->nblock_used++;
567 463563 29 for (i = 0; i < nblock; i++) {
575 0 29 if (s->blockRandomised) {
577 0 0 BZ_GET_FAST(s->k0); s->nblock_used++;
578 0 0 BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
0 0 BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
580 0 29 BZ_GET_FAST(s->k0); s->nblock_used++;
591 29 39 GET_UCHAR(BZ_X_ENDHDR_2, uc);
10 29 GET_UCHAR(BZ_X_ENDHDR_2, uc);
0 29 GET_UCHAR(BZ_X_ENDHDR_2, uc);
592 0 29 if (uc != 0x72) RETURN(BZ_DATA_ERROR);
593 29 39 GET_UCHAR(BZ_X_ENDHDR_3, uc);
10 29 GET_UCHAR(BZ_X_ENDHDR_3, uc);
0 29 GET_UCHAR(BZ_X_ENDHDR_3, uc);
594 0 29 if (uc != 0x45) RETURN(BZ_DATA_ERROR);
595 29 39 GET_UCHAR(BZ_X_ENDHDR_4, uc);
10 29 GET_UCHAR(BZ_X_ENDHDR_4, uc);
0 29 GET_UCHAR(BZ_X_ENDHDR_4, uc);
596 0 29 if (uc != 0x38) RETURN(BZ_DATA_ERROR);
597 29 39 GET_UCHAR(BZ_X_ENDHDR_5, uc);
10 29 GET_UCHAR(BZ_X_ENDHDR_5, uc);
0 29 GET_UCHAR(BZ_X_ENDHDR_5, uc);
598 0 29 if (uc != 0x50) RETURN(BZ_DATA_ERROR);
599 29 39 GET_UCHAR(BZ_X_ENDHDR_6, uc);
10 29 GET_UCHAR(BZ_X_ENDHDR_6, uc);
0 29 GET_UCHAR(BZ_X_ENDHDR_6, uc);
600 0 29 if (uc != 0x90) RETURN(BZ_DATA_ERROR);
603 29 39 GET_UCHAR(BZ_X_CCRC_1, uc);
10 29 GET_UCHAR(BZ_X_CCRC_1, uc);
0 29 GET_UCHAR(BZ_X_CCRC_1, uc);
605 29 39 GET_UCHAR(BZ_X_CCRC_2, uc);
10 29 GET_UCHAR(BZ_X_CCRC_2, uc);
0 29 GET_UCHAR(BZ_X_CCRC_2, uc);
607 29 39 GET_UCHAR(BZ_X_CCRC_3, uc);
10 29 GET_UCHAR(BZ_X_CCRC_3, uc);
0 29 GET_UCHAR(BZ_X_CCRC_3, uc);
609 29 39 GET_UCHAR(BZ_X_CCRC_4, uc);
10 29 GET_UCHAR(BZ_X_CCRC_4, uc);
0 29 GET_UCHAR(BZ_X_CCRC_4, uc);