| 2607 | // |
| 2608 | |
| 2609 | static bool hufBuildDecTable(const long long *hcode, // i : encoding table |
| 2610 | int im, // i : min index in hcode |
| 2611 | int iM, // i : max index in hcode |
| 2612 | HufDec *hdecod) // o: (allocated by caller) |
| 2613 | // decoding table [HUF_DECSIZE] |
| 2614 | { |
| 2615 | // |
| 2616 | // Init hashtable & loop on all codes. |
| 2617 | // Assumes that hufClearDecTable(hdecod) has already been called. |
| 2618 | // |
| 2619 | |
| 2620 | for (; im <= iM; im++) { |
| 2621 | long long c = hufCode(hcode[im]); |
| 2622 | int l = hufLength(hcode[im]); |
| 2623 | |
| 2624 | if (c >> l) { |
| 2625 | // |
| 2626 | // Error: c is supposed to be an l-bit code, |
| 2627 | // but c contains a value that is greater |
| 2628 | // than the largest l-bit number. |
| 2629 | // |
| 2630 | |
| 2631 | // invalidTableEntry(); |
| 2632 | return false; |
| 2633 | } |
| 2634 | |
| 2635 | if (l > HUF_DECBITS) { |
| 2636 | // |
| 2637 | // Long code: add a secondary entry |
| 2638 | // |
| 2639 | |
| 2640 | HufDec *pl = hdecod + (c >> (l - HUF_DECBITS)); |
| 2641 | |
| 2642 | if (pl->len) { |
| 2643 | // |
| 2644 | // Error: a short code has already |
| 2645 | // been stored in table entry *pl. |
| 2646 | // |
| 2647 | |
| 2648 | // invalidTableEntry(); |
| 2649 | return false; |
| 2650 | } |
| 2651 | |
| 2652 | pl->lit++; |
| 2653 | |
| 2654 | if (pl->p) { |
| 2655 | unsigned int *p = pl->p; |
| 2656 | pl->p = new unsigned int[pl->lit]; |
| 2657 | |
| 2658 | for (unsigned int i = 0; i < pl->lit - 1u; ++i) pl->p[i] = p[i]; |
| 2659 | |
| 2660 | delete[] p; |
| 2661 | } else { |
| 2662 | pl->p = new unsigned int[1]; |
| 2663 | } |
| 2664 | |
| 2665 | pl->p[pl->lit - 1] = im; |
| 2666 | } else if (l) { |
no test coverage detected