| 2526 | // |
| 2527 | |
| 2528 | static bool hufUnpackEncTable( |
| 2529 | const char **pcode, // io: ptr to packed table (updated) |
| 2530 | int ni, // i : input size (in bytes) |
| 2531 | int im, // i : min hcode index |
| 2532 | int iM, // i : max hcode index |
| 2533 | long long *hcode) // o: encoding table [HUF_ENCSIZE] |
| 2534 | { |
| 2535 | memset(hcode, 0, sizeof(long long) * HUF_ENCSIZE); |
| 2536 | |
| 2537 | const char *p = *pcode; |
| 2538 | long long c = 0; |
| 2539 | int lc = 0; |
| 2540 | |
| 2541 | for (; im <= iM; im++) { |
| 2542 | if (p - *pcode >= ni) { |
| 2543 | return false; |
| 2544 | } |
| 2545 | |
| 2546 | long long l = hcode[im] = getBits(6, c, lc, p); // code length |
| 2547 | |
| 2548 | if (l == (long long)LONG_ZEROCODE_RUN) { |
| 2549 | if (p - *pcode > ni) { |
| 2550 | return false; |
| 2551 | } |
| 2552 | |
| 2553 | int zerun = getBits(8, c, lc, p) + SHORTEST_LONG_RUN; |
| 2554 | |
| 2555 | if (im + zerun > iM + 1) { |
| 2556 | return false; |
| 2557 | } |
| 2558 | |
| 2559 | while (zerun--) hcode[im++] = 0; |
| 2560 | |
| 2561 | im--; |
| 2562 | } else if (l >= (long long)SHORT_ZEROCODE_RUN) { |
| 2563 | int zerun = l - SHORT_ZEROCODE_RUN + 2; |
| 2564 | |
| 2565 | if (im + zerun > iM + 1) { |
| 2566 | return false; |
| 2567 | } |
| 2568 | |
| 2569 | while (zerun--) hcode[im++] = 0; |
| 2570 | |
| 2571 | im--; |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | *pcode = const_cast<char *>(p); |
| 2576 | |
| 2577 | hufCanonicalCodeTable(hcode); |
| 2578 | |
| 2579 | return true; |
| 2580 | } |
| 2581 | |
| 2582 | // |
| 2583 | // DECODING TABLE BUILDING |
no test coverage detected