| 2596 | // |
| 2597 | |
| 2598 | static bool hufUnpackEncTable( |
| 2599 | const char **pcode, // io: ptr to packed table (updated) |
| 2600 | int ni, // i : input size (in bytes) |
| 2601 | int im, // i : min hcode index |
| 2602 | int iM, // i : max hcode index |
| 2603 | long long *hcode) // o: encoding table [HUF_ENCSIZE] |
| 2604 | { |
| 2605 | memset(hcode, 0, sizeof(long long) * HUF_ENCSIZE); |
| 2606 | |
| 2607 | const char *p = *pcode; |
| 2608 | long long c = 0; |
| 2609 | int lc = 0; |
| 2610 | |
| 2611 | for (; im <= iM; im++) { |
| 2612 | if (p - *pcode >= ni) { |
| 2613 | return false; |
| 2614 | } |
| 2615 | |
| 2616 | long long l = hcode[im] = getBits(6, c, lc, p); // code length |
| 2617 | |
| 2618 | if (l == (long long)LONG_ZEROCODE_RUN) { |
| 2619 | if (p - *pcode > ni) { |
| 2620 | return false; |
| 2621 | } |
| 2622 | |
| 2623 | int zerun = getBits(8, c, lc, p) + SHORTEST_LONG_RUN; |
| 2624 | |
| 2625 | if (im + zerun > iM + 1) { |
| 2626 | return false; |
| 2627 | } |
| 2628 | |
| 2629 | while (zerun--) hcode[im++] = 0; |
| 2630 | |
| 2631 | im--; |
| 2632 | } else if (l >= (long long)SHORT_ZEROCODE_RUN) { |
| 2633 | int zerun = l - SHORT_ZEROCODE_RUN + 2; |
| 2634 | |
| 2635 | if (im + zerun > iM + 1) { |
| 2636 | return false; |
| 2637 | } |
| 2638 | |
| 2639 | while (zerun--) hcode[im++] = 0; |
| 2640 | |
| 2641 | im--; |
| 2642 | } |
| 2643 | } |
| 2644 | |
| 2645 | *pcode = const_cast<char *>(p); |
| 2646 | |
| 2647 | hufCanonicalCodeTable(hcode); |
| 2648 | |
| 2649 | return true; |
| 2650 | } |
| 2651 | |
| 2652 | // |
| 2653 | // DECODING TABLE BUILDING |
no test coverage detected