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 51112 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 7750 1401 GET_BIT(BZ_X_SELECTOR_3, uc);
434 967 GET_BIT(BZ_X_SELECTOR_3, uc);
0 967 GET_BIT(BZ_X_SELECTOR_3, uc);
296 2260 5490 if (uc == 0) break;
298 0 5490 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 5490 2260 while (v > 0) { pos[v] = pos[v-1]; v--; }
324 81 29 for (t = 0; t < nGroups; t++) {
325 81 60 GET_BITS(BZ_X_CODING_1, curr, 5);
15 45 GET_BITS(BZ_X_CODING_1, curr, 5);
0 45 GET_BITS(BZ_X_CODING_1, curr, 5);
326 7154 81 for (i = 0; i < alphaSize; i++) {
328 11679 0 if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
0 11679 if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
329 11679 1794 GET_BIT(BZ_X_CODING_2, uc);
340 1454 GET_BIT(BZ_X_CODING_2, uc);
0 1454 GET_BIT(BZ_X_CODING_2, uc);
330 7154 4525 if (uc == 0) break;
331 4525 680 GET_BIT(BZ_X_CODING_3, uc);
104 576 GET_BIT(BZ_X_CODING_3, uc);
0 576 GET_BIT(BZ_X_CODING_3, uc);
332 2310 2215 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 119 7035 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
344 190 6964 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 68 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
29 39 GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
39 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 110208 476 if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
167 110041 if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
397 0 2067 if (N >= 2*1024*1024) RETURN(BZ_DATA_ERROR);
398 1086 981 if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
399 981 0 if (nextSym == BZ_RUNB) es = es + (1+1) * N;
401 45 2022 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 45 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
2067 757 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
177 580 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 580 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 3918 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
2067 1851 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
1851 284 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
28 256 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 256 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
2067 0 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
0 2067 GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
403 610 1457 while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
814 643 while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
409 0 643 if (s->smallDecompress)
410 0 0 while (es > 0) {
411 0 0 if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
417 353522 643 while (es > 0) {
418 0 353522 if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
428 0 110041 if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
436 7027 103014 if (nn < MTFL_SIZE) {
440 11180 7027 while (nn > 3) {
448 11209 7027 while (nn > 0) {
458 770976 103014 while (pp > s->mtfbase[lno]) {
462 821155 103014 while (lno > 0) {
470 26 102988 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 110041 if (s->smallDecompress)
490 2186 107855 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 2186 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110041 137706 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
43270 94436 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 94436 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 220046 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110041 110005 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110005 20675 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
6288 14387 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 14387 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
110041 0 GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
0 110041 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);