- unsigned curpos = 0;
- unsigned huffsym;
- int match_len;
- int ret = 0;
-
- while (curpos < uncompressed_len) {
- ret = read_huffsym(istream, decode_table, lens,
- XPRESS_NUM_SYMBOLS, XPRESS_TABLEBITS,
- &huffsym, XPRESS_MAX_CODEWORD_LEN);
- if (ret != 0)
- break;
-
- if (huffsym < XPRESS_NUM_CHARS) {
- uncompressed_data[curpos++] = huffsym;
+ input_idx_t curpos;
+ unsigned match_len;
+
+ for (curpos = 0; curpos < uncompressed_len; curpos += match_len) {
+ unsigned sym;
+ int ret;
+
+ if (unlikely(bitstream_ensure_bits(istream, 16)))
+ return -1;
+
+ if (unlikely(read_huffsym(istream, decode_table, lens,
+ XPRESS_NUM_SYMBOLS, XPRESS_TABLEBITS,
+ &sym, XPRESS_MAX_CODEWORD_LEN)))
+ return -1;
+
+ if (sym < XPRESS_NUM_CHARS) {
+ /* Literal */
+ uncompressed_data[curpos] = sym;
+ match_len = 1;