Fix some more compiler warnings in the decoder.

This commit is contained in:
Zoltan Szabadka 2015-10-05 10:23:32 +02:00
parent 498f1ecebf
commit bacc734997
10 changed files with 153 additions and 141 deletions

View File

@ -36,7 +36,9 @@ extern "C" {
/* Masking with this expression turns to a single "Unsigned Bit Field Extract" /* Masking with this expression turns to a single "Unsigned Bit Field Extract"
UBFX instruction on ARM. */ UBFX instruction on ARM. */
static BROTLI_INLINE uint32_t BitMask(int n) { return ~((0xffffffff) << n); } static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
return ~((0xffffffffU) << n);
}
typedef struct { typedef struct {
#if (BROTLI_64_BITS) #if (BROTLI_64_BITS)
@ -190,7 +192,7 @@ static BROTLI_INLINE uint64_t BrotliLoad64LE(const uint8_t* in) {
n_bits should be in the range [1..24] for regular build. For portable n_bits should be in the range [1..24] for regular build. For portable
non-64-bit little endian build only 16 bits are safe to request. */ non-64-bit little endian build only 16 bits are safe to request. */
static BROTLI_INLINE void BrotliFillBitWindow( static BROTLI_INLINE void BrotliFillBitWindow(
BrotliBitReader* const br, int n_bits) { BrotliBitReader* const br, uint32_t n_bits) {
#if (BROTLI_64_BITS) #if (BROTLI_64_BITS)
if (!BROTLI_ALIGNED_READ && IS_CONSTANT(n_bits) && (n_bits <= 8)) { if (!BROTLI_ALIGNED_READ && IS_CONSTANT(n_bits) && (n_bits <= 8)) {
if (br->bit_pos_ >= 56) { if (br->bit_pos_ >= 56) {
@ -254,14 +256,14 @@ static BROTLI_INLINE void BrotliPullByte(BrotliBitReader* const br) {
/* Like BrotliGetBits, but does not mask the result, it is only guaranteed /* Like BrotliGetBits, but does not mask the result, it is only guaranteed
that it has minimum n_bits. */ that it has minimum n_bits. */
static BROTLI_INLINE uint32_t BrotliGetBitsUnmasked( static BROTLI_INLINE uint32_t BrotliGetBitsUnmasked(
BrotliBitReader* const br, int n_bits) { BrotliBitReader* const br, uint32_t n_bits) {
BrotliFillBitWindow(br, n_bits); BrotliFillBitWindow(br, n_bits);
return (uint32_t)(br->val_ >> br->bit_pos_); return (uint32_t)(br->val_ >> br->bit_pos_);
} }
/* Returns the specified number of bits from br without advancing bit pos. */ /* Returns the specified number of bits from br without advancing bit pos. */
static BROTLI_INLINE uint32_t BrotliGetBits( static BROTLI_INLINE uint32_t BrotliGetBits(
BrotliBitReader* const br, int n_bits) { BrotliBitReader* const br, uint32_t n_bits) {
BrotliFillBitWindow(br, n_bits); BrotliFillBitWindow(br, n_bits);
return (uint32_t)(br->val_ >> br->bit_pos_) & BitMask(n_bits); return (uint32_t)(br->val_ >> br->bit_pos_) & BitMask(n_bits);
} }
@ -275,19 +277,19 @@ static BROTLI_INLINE void BrotliDropBits(
/* Reads the specified number of bits from br and advances the bit pos. /* Reads the specified number of bits from br and advances the bit pos.
Precondition: accumulator MUST contain at least n_bits. */ Precondition: accumulator MUST contain at least n_bits. */
static BROTLI_INLINE void BrotliTakeBits( static BROTLI_INLINE void BrotliTakeBits(
BrotliBitReader* const br, int n_bits, uint32_t* val) { BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
*val = (uint32_t)(br->val_ >> br->bit_pos_) & BitMask(n_bits); *val = (uint32_t)(br->val_ >> br->bit_pos_) & BitMask(n_bits);
#ifdef BROTLI_DECODE_DEBUG #ifdef BROTLI_DECODE_DEBUG
printf("[BrotliReadBits] %d %d %d val: %6x\n", printf("[BrotliReadBits] %d %d %d val: %6x\n",
(int)br->avail_in, (int)br->bit_pos_, n_bits, (int)*val); (int)br->avail_in, (int)br->bit_pos_, n_bits, (int)*val);
#endif #endif
br->bit_pos_ += (uint32_t)n_bits; br->bit_pos_ += n_bits;
} }
/* Reads the specified number of bits from br and advances the bit pos. /* Reads the specified number of bits from br and advances the bit pos.
Assumes that there is enough input to perform BrotliFillBitWindow. */ Assumes that there is enough input to perform BrotliFillBitWindow. */
static BROTLI_INLINE uint32_t BrotliReadBits( static BROTLI_INLINE uint32_t BrotliReadBits(
BrotliBitReader* const br, int n_bits) { BrotliBitReader* const br, uint32_t n_bits) {
if (BROTLI_64_BITS || (n_bits <= 16)) { if (BROTLI_64_BITS || (n_bits <= 16)) {
uint32_t val; uint32_t val;
BrotliFillBitWindow(br, n_bits); BrotliFillBitWindow(br, n_bits);
@ -307,7 +309,7 @@ static BROTLI_INLINE uint32_t BrotliReadBits(
/* Tries to read the specified amount of bits. Returns 0, if there is not /* Tries to read the specified amount of bits. Returns 0, if there is not
enough input. */ enough input. */
static BROTLI_INLINE int BrotliSafeReadBits( static BROTLI_INLINE int BrotliSafeReadBits(
BrotliBitReader* const br, int n_bits, uint32_t* val) { BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
while (br->bit_pos_ + (uint32_t)n_bits > (sizeof(br->val_) << 3)) { while (br->bit_pos_ + (uint32_t)n_bits > (sizeof(br->val_) << 3)) {
if (br->avail_in == 0) { if (br->avail_in == 0) {
return 0; return 0;
@ -321,7 +323,7 @@ static BROTLI_INLINE int BrotliSafeReadBits(
/* Advances the bit reader position to the next byte boundary and verifies /* Advances the bit reader position to the next byte boundary and verifies
that any skipped bits are set to zero. */ that any skipped bits are set to zero. */
static BROTLI_INLINE int BrotliJumpToByteBoundary(BrotliBitReader* br) { static BROTLI_INLINE int BrotliJumpToByteBoundary(BrotliBitReader* br) {
int pad_bits_count = (64 - (int)br->bit_pos_) & 0x7; uint32_t pad_bits_count = (64 - (int)br->bit_pos_) & 0x7;
uint32_t pad_bits = 0; uint32_t pad_bits = 0;
if (pad_bits_count != 0) { if (pad_bits_count != 0) {
BrotliTakeBits(br, pad_bits_count, &pad_bits); BrotliTakeBits(br, pad_bits_count, &pad_bits);
@ -332,8 +334,8 @@ static BROTLI_INLINE int BrotliJumpToByteBoundary(BrotliBitReader* br) {
/* Peeks a byte at specified offset. /* Peeks a byte at specified offset.
Precondition: bit reader is parked to a byte boundary. Precondition: bit reader is parked to a byte boundary.
Returns -1 if operation is not feasible. */ Returns -1 if operation is not feasible. */
static BROTLI_INLINE int BrotliPeekByte(BrotliBitReader* br, int offset) { static BROTLI_INLINE int BrotliPeekByte(BrotliBitReader* br, size_t offset) {
int bytes_left = (int)(sizeof(br->val_) - (br->bit_pos_ >> 3)); size_t bytes_left = sizeof(br->val_) - (br->bit_pos_ >> 3);
if (br->bit_pos_ & 7) { if (br->bit_pos_ & 7) {
return -1; return -1;
} }

View File

@ -48,13 +48,13 @@ extern "C" {
static const uint8_t kDefaultCodeLength = 8; static const uint8_t kDefaultCodeLength = 8;
static const uint8_t kCodeLengthRepeatCode = 16; static const uint8_t kCodeLengthRepeatCode = 16;
static const int kNumLiteralCodes = 256; static const uint32_t kNumLiteralCodes = 256;
static const int kNumInsertAndCopyCodes = 704; static const uint32_t kNumInsertAndCopyCodes = 704;
static const int kNumBlockLengthCodes = 26; static const uint32_t kNumBlockLengthCodes = 26;
static const int kLiteralContextBits = 6; static const int kLiteralContextBits = 6;
static const int kDistanceContextBits = 2; static const int kDistanceContextBits = 2;
#define HUFFMAN_TABLE_BITS 8 #define HUFFMAN_TABLE_BITS 8U
#define HUFFMAN_TABLE_MASK 0xff #define HUFFMAN_TABLE_MASK 0xff
#define CODE_LENGTH_CODES 18 #define CODE_LENGTH_CODES 18
@ -115,7 +115,7 @@ static BROTLI_INLINE BROTLI_NO_ASAN void memmove16(
/* Decodes a number in the range [0..255], by reading 1 - 11 bits. */ /* Decodes a number in the range [0..255], by reading 1 - 11 bits. */
static BROTLI_NOINLINE BrotliResult DecodeVarLenUint8(BrotliState* s, static BROTLI_NOINLINE BrotliResult DecodeVarLenUint8(BrotliState* s,
BrotliBitReader* br, int* value) { BrotliBitReader* br, uint32_t* value) {
uint32_t bits; uint32_t bits;
switch (s->substate_decode_uint8) { switch (s->substate_decode_uint8) {
case BROTLI_STATE_DECODE_UINT8_NONE: case BROTLI_STATE_DECODE_UINT8_NONE:
@ -139,7 +139,7 @@ static BROTLI_NOINLINE BrotliResult DecodeVarLenUint8(BrotliState* s,
return BROTLI_RESULT_SUCCESS; return BROTLI_RESULT_SUCCESS;
} }
/* Use output value as a temporary storage. It MUST be persisted. */ /* Use output value as a temporary storage. It MUST be persisted. */
*value = (int)bits; *value = bits;
/* No break, transit to the next state. */ /* No break, transit to the next state. */
case BROTLI_STATE_DECODE_UINT8_LONG: case BROTLI_STATE_DECODE_UINT8_LONG:
@ -147,7 +147,7 @@ static BROTLI_NOINLINE BrotliResult DecodeVarLenUint8(BrotliState* s,
s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_LONG; s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_LONG;
return BROTLI_RESULT_NEEDS_MORE_INPUT; return BROTLI_RESULT_NEEDS_MORE_INPUT;
} }
*value = (1 << *value) + (int)bits; *value = (1U << *value) + bits;
s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE; s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
return BROTLI_RESULT_SUCCESS; return BROTLI_RESULT_SUCCESS;
@ -275,16 +275,16 @@ static BrotliResult BROTLI_NOINLINE DecodeMetaBlockLength(BrotliState* s,
} }
/* Decodes the next Huffman code from bit-stream. Reads 0 - 15 bits. */ /* Decodes the next Huffman code from bit-stream. Reads 0 - 15 bits. */
static BROTLI_INLINE int ReadSymbol(const HuffmanCode* table, static BROTLI_INLINE uint32_t ReadSymbol(const HuffmanCode* table,
BrotliBitReader* br) { BrotliBitReader* br) {
/* Read the bits for two reads at once. */ /* Read the bits for two reads at once. */
uint32_t val = BrotliGetBitsUnmasked(br, 15); uint32_t val = BrotliGetBitsUnmasked(br, 15);
table += val & HUFFMAN_TABLE_MASK; table += val & HUFFMAN_TABLE_MASK;
if (table->bits > HUFFMAN_TABLE_BITS) { if (table->bits > HUFFMAN_TABLE_BITS) {
int nbits = table->bits - HUFFMAN_TABLE_BITS; uint32_t nbits = table->bits - HUFFMAN_TABLE_BITS;
BrotliDropBits(br, HUFFMAN_TABLE_BITS); BrotliDropBits(br, HUFFMAN_TABLE_BITS);
table += table->value; table += table->value;
table += (int)(val >> HUFFMAN_TABLE_BITS) & (int)BitMask(nbits); table += (val >> HUFFMAN_TABLE_BITS) & BitMask(nbits);
} }
BrotliDropBits(br, table->bits); BrotliDropBits(br, table->bits);
return table->value; return table->value;
@ -293,8 +293,8 @@ static BROTLI_INLINE int ReadSymbol(const HuffmanCode* table,
/* Makes a look-up in first level Huffman table. Peeks 8 bits. */ /* Makes a look-up in first level Huffman table. Peeks 8 bits. */
static BROTLI_INLINE void PreloadSymbol(const HuffmanCode* table, static BROTLI_INLINE void PreloadSymbol(const HuffmanCode* table,
BrotliBitReader* br, BrotliBitReader* br,
unsigned* bits, uint32_t* bits,
unsigned* value) { uint32_t* value) {
table += BrotliGetBits(br, HUFFMAN_TABLE_BITS); table += BrotliGetBits(br, HUFFMAN_TABLE_BITS);
*bits = table->bits; *bits = table->bits;
*value = table->value; *value = table->value;
@ -302,17 +302,17 @@ static BROTLI_INLINE void PreloadSymbol(const HuffmanCode* table,
/* Decodes the next Huffman code using data prepared by PreloadSymbol. /* Decodes the next Huffman code using data prepared by PreloadSymbol.
Reads 0 - 15 bits. Also peeks 8 following bits. */ Reads 0 - 15 bits. Also peeks 8 following bits. */
static BROTLI_INLINE unsigned ReadPreloadedSymbol(const HuffmanCode* table, static BROTLI_INLINE uint32_t ReadPreloadedSymbol(const HuffmanCode* table,
BrotliBitReader* br, BrotliBitReader* br,
unsigned* bits, uint32_t* bits,
unsigned* value) { uint32_t* value) {
unsigned result = *value; uint32_t result = *value;
if (PREDICT_FALSE(*bits > HUFFMAN_TABLE_BITS)) { if (PREDICT_FALSE(*bits > HUFFMAN_TABLE_BITS)) {
uint32_t val = BrotliGetBitsUnmasked(br, 15); uint32_t val = BrotliGetBitsUnmasked(br, 15);
const HuffmanCode* ext = table + (val & HUFFMAN_TABLE_MASK) + *value; const HuffmanCode* ext = table + (val & HUFFMAN_TABLE_MASK) + *value;
int mask = (int)BitMask((int)(*bits - HUFFMAN_TABLE_BITS)); uint32_t mask = BitMask((*bits - HUFFMAN_TABLE_BITS));
BrotliDropBits(br, HUFFMAN_TABLE_BITS); BrotliDropBits(br, HUFFMAN_TABLE_BITS);
ext += (int)(val >> HUFFMAN_TABLE_BITS) & mask; ext += (val >> HUFFMAN_TABLE_BITS) & mask;
BrotliDropBits(br, ext->bits); BrotliDropBits(br, ext->bits);
result = ext->value; result = ext->value;
} else { } else {
@ -322,8 +322,8 @@ static BROTLI_INLINE unsigned ReadPreloadedSymbol(const HuffmanCode* table,
return result; return result;
} }
static BROTLI_INLINE int Log2Floor(int x) { static BROTLI_INLINE uint32_t Log2Floor(uint32_t x) {
int result = 0; uint32_t result = 0;
while (x) { while (x) {
x >>= 1; x >>= 1;
++result; ++result;
@ -343,12 +343,12 @@ static BROTLI_INLINE int Log2Floor(int x) {
B.2) Decoded table is used to decode code lengths of symbols in resulting B.2) Decoded table is used to decode code lengths of symbols in resulting
Huffman table. In worst case 3520 bits are read. Huffman table. In worst case 3520 bits are read.
*/ */
static BrotliResult ReadHuffmanCode(int alphabet_size, static BrotliResult ReadHuffmanCode(uint32_t alphabet_size,
HuffmanCode* table, HuffmanCode* table,
int* opt_table_size, uint32_t* opt_table_size,
BrotliState* s) { BrotliState* s) {
BrotliBitReader* br = &s->br; BrotliBitReader* br = &s->br;
int i; uint32_t i;
/* Unnecessary masking, but might be good for safety. */ /* Unnecessary masking, but might be good for safety. */
alphabet_size &= 0x3ff; alphabet_size &= 0x3ff;
/* State machine */ /* State machine */
@ -357,14 +357,14 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
if (!BrotliCheckInputAmount(br, 32)) { if (!BrotliCheckInputAmount(br, 32)) {
return BROTLI_RESULT_NEEDS_MORE_INPUT; return BROTLI_RESULT_NEEDS_MORE_INPUT;
} }
i = (int)BrotliReadBits(br, 2); i = BrotliReadBits(br, 2);
/* The value is used as follows: /* The value is used as follows:
1 for simple code; 1 for simple code;
0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths */ 0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths */
BROTLI_LOG_UINT((unsigned)i); BROTLI_LOG_UINT(i);
if (i == 1) { if (i == 1) {
/* Read symbols, codes & code lengths directly. */ /* Read symbols, codes & code lengths directly. */
int max_bits = Log2Floor(alphabet_size - 1); uint32_t max_bits = Log2Floor(alphabet_size - 1);
uint32_t num_symbols = BrotliReadBits(br, 2); uint32_t num_symbols = BrotliReadBits(br, 2);
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
s->symbols_lists_array[i] = 0; s->symbols_lists_array[i] = 0;
@ -380,7 +380,7 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
BROTLI_LOG_UINT(s->symbols_lists_array[i]); BROTLI_LOG_UINT(s->symbols_lists_array[i]);
} while (++i <= num_symbols); } while (++i <= num_symbols);
for (i = 0; i < num_symbols; ++i) { for (i = 0; i < num_symbols; ++i) {
int k = i + 1; uint32_t k = i + 1;
for (; k <= num_symbols; ++k) { for (; k <= num_symbols; ++k) {
if (s->symbols_lists_array[i] == s->symbols_lists_array[k]) { if (s->symbols_lists_array[i] == s->symbols_lists_array[k]) {
return BROTLI_FAILURE(); return BROTLI_FAILURE();
@ -432,8 +432,8 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
s->code_length_histo); s->code_length_histo);
memset(&s->code_length_histo[0], 0, sizeof(s->code_length_histo)); memset(&s->code_length_histo[0], 0, sizeof(s->code_length_histo));
for (i = 0; i <= BROTLI_HUFFMAN_MAX_CODE_LENGTH; ++i) { for (i = 0; i <= BROTLI_HUFFMAN_MAX_CODE_LENGTH; ++i) {
s->next_symbol[i] = i - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1); s->next_symbol[i] = (int)i - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
s->symbol_lists[i - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1)] = 0xFFFF; s->symbol_lists[(int)i - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1)] = 0xFFFF;
} }
s->symbol = 0; s->symbol = 0;
@ -477,7 +477,7 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
} }
symbol++; symbol++;
} else { /* code_len == 16..17, extra_bits == 2..3 */ } else { /* code_len == 16..17, extra_bits == 2..3 */
uint32_t repeat_delta = BrotliReadBits(br, code_len - 14); uint32_t repeat_delta = BrotliReadBits(br, code_len - 14U);
uint32_t old_repeat; uint32_t old_repeat;
uint8_t new_len = 0; uint8_t new_len = 0;
if (code_len == kCodeLengthRepeatCode) { if (code_len == kCodeLengthRepeatCode) {
@ -501,12 +501,12 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
} }
if (repeat_code_len != 0) { if (repeat_code_len != 0) {
unsigned last = symbol + repeat_delta; unsigned last = symbol + repeat_delta;
i = next_symbol[repeat_code_len]; int next = next_symbol[repeat_code_len];
do { do {
symbol_lists[i] = (uint16_t)symbol; symbol_lists[next] = (uint16_t)symbol;
i = (int)symbol; next = (int)symbol;
} while (++symbol != last); } while (++symbol != last);
next_symbol[repeat_code_len] = i; next_symbol[repeat_code_len] = next;
space -= repeat_delta << (15 - repeat_code_len); space -= repeat_delta << (15 - repeat_code_len);
code_length_histo[repeat_code_len] = (uint16_t) code_length_histo[repeat_code_len] = (uint16_t)
(code_length_histo[repeat_code_len] + repeat_delta); (code_length_histo[repeat_code_len] + repeat_delta);
@ -520,7 +520,7 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
return BROTLI_FAILURE(); return BROTLI_FAILURE();
} }
{ {
int table_size = BrotliBuildHuffmanTable( uint32_t table_size = BrotliBuildHuffmanTable(
table, HUFFMAN_TABLE_BITS, symbol_lists, table, HUFFMAN_TABLE_BITS, symbol_lists,
s->code_length_histo); s->code_length_histo);
if (opt_table_size) { if (opt_table_size) {
@ -539,8 +539,8 @@ static BrotliResult ReadHuffmanCode(int alphabet_size,
/* Decodes a block length by reading 3..39 bits. */ /* Decodes a block length by reading 3..39 bits. */
static BROTLI_INLINE int ReadBlockLength(const HuffmanCode* table, static BROTLI_INLINE int ReadBlockLength(const HuffmanCode* table,
BrotliBitReader* br) { BrotliBitReader* br) {
int code; uint32_t code;
int nbits; uint32_t nbits;
code = ReadSymbol(table, br); code = ReadSymbol(table, br);
nbits = kBlockLengthPrefixCode[code].nbits; /* nbits == 2..24 */ nbits = kBlockLengthPrefixCode[code].nbits; /* nbits == 2..24 */
return kBlockLengthPrefixCode[code].offset + (int)BrotliReadBits(br, nbits); return kBlockLengthPrefixCode[code].offset + (int)BrotliReadBits(br, nbits);
@ -561,11 +561,11 @@ static BROTLI_INLINE int ReadBlockLength(const HuffmanCode* table,
Most of input values are 0 and 1. To reduce number of branches, we replace Most of input values are 0 and 1. To reduce number of branches, we replace
inner for loop with do-while. inner for loop with do-while.
*/ */
static BROTLI_NOINLINE void InverseMoveToFrontTransform(uint8_t* v, int v_len, static BROTLI_NOINLINE void InverseMoveToFrontTransform(uint8_t* v,
BrotliState* state) { uint32_t v_len, BrotliState* state) {
/* Reinitialize elements that could have been changed. */ /* Reinitialize elements that could have been changed. */
int i = 4; uint32_t i = 4;
int upper_bound = state->mtf_upper_bound; uint32_t upper_bound = state->mtf_upper_bound;
uint8_t* mtf = state->mtf; uint8_t* mtf = state->mtf;
/* Load endian-aware constant. */ /* Load endian-aware constant. */
const uint8_t b0123[4] = {0, 1, 2, 3}; const uint8_t b0123[4] = {0, 1, 2, 3};
@ -585,8 +585,8 @@ static BROTLI_NOINLINE void InverseMoveToFrontTransform(uint8_t* v, int v_len,
for (i = 0; i < v_len; ++i) { for (i = 0; i < v_len; ++i) {
int index = v[i]; int index = v[i];
uint8_t value = mtf[index]; uint8_t value = mtf[index];
upper_bound |= v[i];
v[i] = value; v[i] = value;
upper_bound |= index;
do { do {
index--; index--;
mtf[index + 1] = mtf[index]; mtf[index + 1] = mtf[index];
@ -598,7 +598,8 @@ static BROTLI_NOINLINE void InverseMoveToFrontTransform(uint8_t* v, int v_len,
} }
/* Expose function for testing. Will be removed by linker as unused. */ /* Expose function for testing. Will be removed by linker as unused. */
void InverseMoveToFrontTransformForTesting(uint8_t* v, int l, BrotliState* s) { void InverseMoveToFrontTransformForTesting(
uint8_t* v, uint32_t l, BrotliState* s) {
InverseMoveToFrontTransform(v, l, s); InverseMoveToFrontTransform(v, l, s);
} }
@ -612,7 +613,7 @@ static BrotliResult HuffmanTreeGroupDecode(HuffmanTreeGroup* group,
s->substate_tree_group = BROTLI_STATE_TREE_GROUP_LOOP; s->substate_tree_group = BROTLI_STATE_TREE_GROUP_LOOP;
} }
while (s->htree_index < group->num_htrees) { while (s->htree_index < group->num_htrees) {
int table_size; uint32_t table_size;
BrotliResult result = BrotliResult result =
ReadHuffmanCode(group->alphabet_size, s->next, &table_size, s); ReadHuffmanCode(group->alphabet_size, s->next, &table_size, s);
if (result != BROTLI_RESULT_SUCCESS) return result; if (result != BROTLI_RESULT_SUCCESS) return result;
@ -633,8 +634,8 @@ static BrotliResult HuffmanTreeGroupDecode(HuffmanTreeGroup* group,
3) Read context map items; "0" values could be run-length encoded. 3) Read context map items; "0" values could be run-length encoded.
4) Optionally, apply InverseMoveToFront transform to the resulting map. 4) Optionally, apply InverseMoveToFront transform to the resulting map.
*/ */
static BrotliResult DecodeContextMap(int context_map_size, static BrotliResult DecodeContextMap(uint32_t context_map_size,
int* num_htrees, uint32_t* num_htrees,
uint8_t** context_map_arg, uint8_t** context_map_arg,
BrotliState* s) { BrotliState* s) {
BrotliBitReader* br = &s->br; BrotliBitReader* br = &s->br;
@ -667,7 +668,7 @@ static BrotliResult DecodeContextMap(int context_map_size,
} }
use_rle_for_zeros = (int)BrotliReadBits(br, 1); use_rle_for_zeros = (int)BrotliReadBits(br, 1);
if (use_rle_for_zeros) { if (use_rle_for_zeros) {
s->max_run_length_prefix = (int)BrotliReadBits(br, 4) + 1; s->max_run_length_prefix = BrotliReadBits(br, 4) + 1;
} else { } else {
s->max_run_length_prefix = 0; s->max_run_length_prefix = 0;
} }
@ -681,10 +682,10 @@ static BrotliResult DecodeContextMap(int context_map_size,
s->substate_context_map = BROTLI_STATE_CONTEXT_MAP_DECODE; s->substate_context_map = BROTLI_STATE_CONTEXT_MAP_DECODE;
/* No break, continue to next state. */ /* No break, continue to next state. */
case BROTLI_STATE_CONTEXT_MAP_DECODE: { case BROTLI_STATE_CONTEXT_MAP_DECODE: {
int context_index = s->context_index; uint32_t context_index = s->context_index;
int max_run_length_prefix = s->max_run_length_prefix; uint32_t max_run_length_prefix = s->max_run_length_prefix;
uint8_t* context_map = *context_map_arg; uint8_t* context_map = *context_map_arg;
int code; uint32_t code;
while (context_index < context_map_size) { while (context_index < context_map_size) {
if (!BrotliCheckInputAmount(br, 32)) { if (!BrotliCheckInputAmount(br, 32)) {
s->context_index = context_index; s->context_index = context_index;
@ -694,8 +695,8 @@ static BrotliResult DecodeContextMap(int context_map_size,
BROTLI_LOG_UINT(code); BROTLI_LOG_UINT(code);
if (code == 0) { if (code == 0) {
context_map[context_index++] = 0; context_map[context_index++] = 0;
} else if (code - max_run_length_prefix <= 0) { } else if (code <= max_run_length_prefix) {
int reps = (1 << code) + (int)BrotliReadBits(br, code); uint32_t reps = (1U << code) + BrotliReadBits(br, code);
BROTLI_LOG_UINT(reps); BROTLI_LOG_UINT(reps);
if (context_index + reps > context_map_size) { if (context_index + reps > context_map_size) {
return BROTLI_FAILURE(); return BROTLI_FAILURE();
@ -721,18 +722,20 @@ static BrotliResult DecodeContextMap(int context_map_size,
/* Decodes a command or literal and updates block type ringbuffer. /* Decodes a command or literal and updates block type ringbuffer.
Reads 0..15 bits. */ Reads 0..15 bits. */
static void DecodeBlockType(const int max_block_type, static void DecodeBlockType(const uint32_t max_block_type,
const HuffmanCode* trees, const HuffmanCode* trees,
int tree_type, int tree_type,
int* ringbuffers, uint32_t* ringbuffers,
BrotliBitReader* br) { BrotliBitReader* br) {
int* ringbuffer = ringbuffers + tree_type * 2; uint32_t* ringbuffer = ringbuffers + tree_type * 2;
int block_type = uint32_t block_type = ReadSymbol(
ReadSymbol(&trees[tree_type * BROTLI_HUFFMAN_MAX_TABLE_SIZE], br) - 2; &trees[tree_type * BROTLI_HUFFMAN_MAX_TABLE_SIZE], br);
if (block_type == -1) { if (block_type == 1) {
block_type = ringbuffer[1] + 1; block_type = ringbuffer[1] + 1;
} else if (block_type == -2) { } else if (block_type == 0) {
block_type = ringbuffer[0]; block_type = ringbuffer[0];
} else {
block_type -= 2;
} }
if (block_type >= max_block_type) { if (block_type >= max_block_type) {
block_type -= max_block_type; block_type -= max_block_type;
@ -746,7 +749,7 @@ static void DecodeBlockType(const int max_block_type,
static void DecodeBlockTypeWithContext(BrotliState* s, static void DecodeBlockTypeWithContext(BrotliState* s,
BrotliBitReader* br) { BrotliBitReader* br) {
uint8_t context_mode; uint8_t context_mode;
int context_offset; uint32_t context_offset;
DecodeBlockType(s->num_block_types[0], s->block_type_trees, 0, DecodeBlockType(s->num_block_types[0], s->block_type_trees, 0,
s->block_type_rb, br); /* Reads 0..15 bits. */ s->block_type_rb, br); /* Reads 0..15 bits. */
s->block_length[0] = ReadBlockLength(s->block_len_trees, br); /* 3..39 bits */ s->block_length[0] = ReadBlockLength(s->block_len_trees, br); /* 3..39 bits */
@ -791,14 +794,14 @@ BrotliResult BROTLI_NOINLINE CopyUncompressedBlockToOutput(BrotliOutput output,
for (;;) { for (;;) {
switch ((int)s->substate_uncompressed) { switch ((int)s->substate_uncompressed) {
case BROTLI_STATE_UNCOMPRESSED_NONE: case BROTLI_STATE_UNCOMPRESSED_NONE:
nbytes = (int)BrotliGetRemainingBytes(&s->br);
/* For short lengths copy byte-by-byte */ /* For short lengths copy byte-by-byte */
if (s->meta_block_remaining_len < 8 || if (s->meta_block_remaining_len < 8 ||
s->meta_block_remaining_len < BrotliGetRemainingBytes(&s->br)) { s->meta_block_remaining_len < nbytes) {
s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_SHORT; s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_SHORT;
break; break;
} }
/* Copy remaining bytes from s->br.buf_ to ringbuffer. */ /* Copy remaining bytes from s->br.buf_ to ringbuffer. */
nbytes = (int)BrotliGetRemainingBytes(&s->br);
BrotliCopyBytes(&s->ringbuffer[pos], &s->br, (size_t)nbytes); BrotliCopyBytes(&s->ringbuffer[pos], &s->br, (size_t)nbytes);
pos += nbytes; pos += nbytes;
s->meta_block_remaining_len -= nbytes; s->meta_block_remaining_len -= nbytes;
@ -879,7 +882,7 @@ int BrotliDecompressedSize(size_t encoded_size,
BrotliBitReader br; BrotliBitReader br;
BrotliState s; BrotliState s;
int next_block_header; int next_block_header;
int offset; size_t offset;
BrotliStateInit(&s); BrotliStateInit(&s);
BrotliInitBitReader(&br, in); BrotliInitBitReader(&br, in);
if (!BrotliReadInput(&br, 1) || !BrotliWarmupBitReader(&br)) { if (!BrotliReadInput(&br, 1) || !BrotliWarmupBitReader(&br)) {
@ -896,13 +899,13 @@ int BrotliDecompressedSize(size_t encoded_size,
if (!s.is_uncompressed || !BrotliJumpToByteBoundary(&br)) { if (!s.is_uncompressed || !BrotliJumpToByteBoundary(&br)) {
return 0; return 0;
} }
next_block_header = BrotliPeekByte(&br, s.meta_block_remaining_len); next_block_header = BrotliPeekByte(&br, (size_t)s.meta_block_remaining_len);
if (next_block_header != -1) { if (next_block_header != -1) {
return (next_block_header & 3) == 3; return (next_block_header & 3) == 3;
} }
/* Currently bit reader can't peek outside of its buffer... */ /* Currently bit reader can't peek outside of its buffer... */
offset = BROTLI_READ_SIZE - (int)BrotliGetRemainingBytes(&br); offset = BROTLI_READ_SIZE - BrotliGetRemainingBytes(&br);
offset += s.meta_block_remaining_len; offset += (size_t)s.meta_block_remaining_len;
return (offset < encoded_size) && ((encoded_buffer[offset] & 3) == 3); return (offset < encoded_size) && ((encoded_buffer[offset] & 3) == 3);
} }
@ -922,7 +925,8 @@ int BROTLI_NOINLINE BrotliAllocateRingBuffer(BrotliState* s,
s->ringbuffer_size = 1 << s->window_bits; s->ringbuffer_size = 1 << s->window_bits;
if (s->is_uncompressed) { if (s->is_uncompressed) {
int next_block_header = BrotliPeekByte(br, s->meta_block_remaining_len); int next_block_header = BrotliPeekByte(br,
(size_t)s->meta_block_remaining_len);
if (next_block_header != -1) { /* Peek succeeded */ if (next_block_header != -1) { /* Peek succeeded */
if ((next_block_header & 3) == 3) { /* ISLAST and ISEMPTY */ if ((next_block_header & 3) == 3) { /* ISLAST and ISEMPTY */
is_last = 1; is_last = 1;
@ -1015,6 +1019,7 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
uint8_t context; uint8_t context;
int pos = s->pos; int pos = s->pos;
int i = s->loop_counter; int i = s->loop_counter;
uint32_t j;
BrotliResult result = BROTLI_RESULT_SUCCESS; BrotliResult result = BROTLI_RESULT_SUCCESS;
BrotliBitReader* br = &s->br; BrotliBitReader* br = &s->br;
int initial_remaining_len; int initial_remaining_len;
@ -1199,9 +1204,9 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
result = BROTLI_RESULT_NEEDS_MORE_INPUT; result = BROTLI_RESULT_NEEDS_MORE_INPUT;
break; break;
} }
s->distance_postfix_bits = (int)BrotliReadBits(br, 2); s->distance_postfix_bits = BrotliReadBits(br, 2);
s->num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES + s->num_direct_distance_codes = NUM_DISTANCE_SHORT_CODES +
((int)BrotliReadBits(br, 4) << s->distance_postfix_bits); (BrotliReadBits(br, 4) << s->distance_postfix_bits);
BROTLI_LOG_UINT(s->num_direct_distance_codes); BROTLI_LOG_UINT(s->num_direct_distance_codes);
BROTLI_LOG_UINT(s->distance_postfix_bits); BROTLI_LOG_UINT(s->distance_postfix_bits);
s->distance_postfix_mask = (int)BitMask(s->distance_postfix_bits); s->distance_postfix_mask = (int)BitMask(s->distance_postfix_bits);
@ -1210,9 +1215,9 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
result = BROTLI_FAILURE(); result = BROTLI_FAILURE();
break; break;
} }
for (i = 0; i < s->num_block_types[0]; ++i) { for (j = 0; j < s->num_block_types[0]; ++j) {
s->context_modes[i] = (uint8_t)(BrotliReadBits(br, 2) << 1); s->context_modes[j] = (uint8_t)(BrotliReadBits(br, 2) << 1);
BROTLI_LOG_ARRAY_INDEX(s->context_modes, i); BROTLI_LOG_ARRAY_INDEX(s->context_modes, j);
} }
s->state = BROTLI_STATE_CONTEXT_MAP_1; s->state = BROTLI_STATE_CONTEXT_MAP_1;
/* No break, continue to next state */ /* No break, continue to next state */
@ -1223,8 +1228,8 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
break; break;
} }
s->trivial_literal_context = 1; s->trivial_literal_context = 1;
for (i = 0; i < s->num_block_types[0] << kLiteralContextBits; i++) { for (j = 0; j < s->num_block_types[0] << kLiteralContextBits; j++) {
if (s->context_map[i] != i >> kLiteralContextBits) { if (s->context_map[j] != j >> kLiteralContextBits) {
s->trivial_literal_context = 0; s->trivial_literal_context = 0;
break; break;
} }
@ -1233,8 +1238,8 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
/* No break, continue to next state */ /* No break, continue to next state */
case BROTLI_STATE_CONTEXT_MAP_2: case BROTLI_STATE_CONTEXT_MAP_2:
{ {
int num_distance_codes = uint32_t num_distance_codes =
s->num_direct_distance_codes + (48 << s->distance_postfix_bits); s->num_direct_distance_codes + (48U << s->distance_postfix_bits);
result = DecodeContextMap( result = DecodeContextMap(
s->num_block_types[2] << kDistanceContextBits, s->num_block_types[2] << kDistanceContextBits,
&s->num_dist_htrees, &s->dist_context_map, s); &s->num_dist_htrees, &s->dist_context_map, s);
@ -1313,7 +1318,7 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
&s->block_len_trees[BROTLI_HUFFMAN_MAX_TABLE_SIZE], br); &s->block_len_trees[BROTLI_HUFFMAN_MAX_TABLE_SIZE], br);
} }
{ {
int cmd_code = ReadSymbol(s->htree_command, br); uint32_t cmd_code = ReadSymbol(s->htree_command, br);
int insert_len_extra = 0; int insert_len_extra = 0;
CmdLutElement v; CmdLutElement v;
--s->block_length[1]; --s->block_length[1];
@ -1340,8 +1345,8 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
case BROTLI_STATE_COMMAND_INNER: case BROTLI_STATE_COMMAND_INNER:
/* Read the literals in the command */ /* Read the literals in the command */
if (s->trivial_literal_context) { if (s->trivial_literal_context) {
unsigned bits; uint32_t bits;
unsigned value; uint32_t value;
PreloadSymbol(s->literal_htree, br, &bits, &value); PreloadSymbol(s->literal_htree, br, &bits, &value);
do { do {
if (!BrotliCheckInputAmount(br, 64)) { if (!BrotliCheckInputAmount(br, 64)) {
@ -1417,7 +1422,7 @@ postDecodeLiterals:
BROTLI_DCHECK(s->distance_code < 0); BROTLI_DCHECK(s->distance_code < 0);
if (s->block_length[2] == 0) { if (s->block_length[2] == 0) {
/* Block switch for distance codes */ /* Block switch for distance codes */
int dist_context_offset; uint32_t dist_context_offset;
DecodeBlockType(s->num_block_types[2], DecodeBlockType(s->num_block_types[2],
s->block_type_trees, 2, s->block_type_trees, 2,
s->block_type_rb, br); /* Reads 0..15 bits. */ s->block_type_rb, br); /* Reads 0..15 bits. */
@ -1429,8 +1434,8 @@ postDecodeLiterals:
s->dist_htree_index = s->dist_context_map_slice[s->distance_context]; s->dist_htree_index = s->dist_context_map_slice[s->distance_context];
} }
--s->block_length[2]; --s->block_length[2];
s->distance_code = s->distance_code = (int)ReadSymbol(
ReadSymbol(s->distance_hgroup.htrees[s->dist_htree_index], br); s->distance_hgroup.htrees[s->dist_htree_index], br);
/* Convert the distance code to the actual distance by possibly */ /* Convert the distance code to the actual distance by possibly */
/* looking up past distances from the s->ringbuffer. */ /* looking up past distances from the s->ringbuffer. */
if ((s->distance_code & ~0xf) == 0) { if ((s->distance_code & ~0xf) == 0) {
@ -1461,22 +1466,22 @@ postDecodeLiterals:
} }
} }
} else { } else {
int distval = s->distance_code - s->num_direct_distance_codes; int distval = s->distance_code - (int)s->num_direct_distance_codes;
if (distval >= 0) { if (distval >= 0) {
int nbits; uint32_t nbits;
int postfix; int postfix;
int offset; int offset;
if (s->distance_postfix_bits == 0) { if (s->distance_postfix_bits == 0) {
nbits = (distval >> 1) + 1; nbits = ((uint32_t)distval >> 1) + 1;
offset = ((2 + (distval & 1)) << nbits) - 4; offset = ((2 + (distval & 1)) << nbits) - 4;
s->distance_code = s->num_direct_distance_codes + s->distance_code = (int)s->num_direct_distance_codes +
offset + (int)BrotliReadBits(br, nbits); offset + (int)BrotliReadBits(br, nbits);
} else { } else {
postfix = distval & s->distance_postfix_mask; postfix = distval & s->distance_postfix_mask;
distval >>= s->distance_postfix_bits; distval >>= s->distance_postfix_bits;
nbits = (distval >> 1) + 1; nbits = ((uint32_t)distval >> 1) + 1;
offset = ((2 + (distval & 1)) << nbits) - 4; offset = ((2 + (distval & 1)) << nbits) - 4;
s->distance_code = s->num_direct_distance_codes + s->distance_code = (int)s->num_direct_distance_codes +
((offset + (int)BrotliReadBits(br, nbits)) << ((offset + (int)BrotliReadBits(br, nbits)) <<
s->distance_postfix_bits) + postfix; s->distance_postfix_bits) + postfix;
} }
@ -1500,7 +1505,7 @@ postReadDistance:
i <= kBrotliMaxDictionaryWordLength) { i <= kBrotliMaxDictionaryWordLength) {
int offset = kBrotliDictionaryOffsetsByLength[i]; int offset = kBrotliDictionaryOffsetsByLength[i];
int word_id = s->distance_code - s->max_distance - 1; int word_id = s->distance_code - s->max_distance - 1;
int shift = kBrotliDictionarySizeBitsByLength[i]; uint32_t shift = kBrotliDictionarySizeBitsByLength[i];
int mask = (int)BitMask(shift); int mask = (int)BitMask(shift);
int word_idx = word_id & mask; int word_idx = word_id & mask;
int transform_idx = word_id >> shift; int transform_idx = word_id >> shift;

View File

@ -152,7 +152,8 @@ void BrotliSetCustomDictionary(
/* Escalate internal functions visibility; for testing purposes only. */ /* Escalate internal functions visibility; for testing purposes only. */
void InverseMoveToFrontTransformForTesting(uint8_t* v, int l, BrotliState* s); void InverseMoveToFrontTransformForTesting(
uint8_t* v, uint32_t l, BrotliState* s);
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */ } /* extern "C" */

View File

@ -32,7 +32,7 @@ static const int kBrotliDictionaryOffsetsByLength[] = {
115968, 118528, 119872, 121280, 122016, 115968, 118528, 119872, 121280, 122016,
}; };
static const int8_t kBrotliDictionarySizeBitsByLength[] = { static const uint8_t kBrotliDictionarySizeBitsByLength[] = {
0, 0, 0, 0, 10, 10, 11, 11, 10, 10, 0, 0, 0, 0, 10, 10, 11, 11, 10, 10,
10, 10, 10, 9, 9, 8, 7, 7, 8, 7, 10, 10, 10, 9, 9, 8, 7, 7, 8, 7,
7, 6, 6, 5, 5, 7, 6, 6, 5, 5,

View File

@ -151,7 +151,7 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table,
if (offset[0] == 0) { if (offset[0] == 0) {
code.bits = 0; code.bits = 0;
code.value = (uint16_t)sorted[0]; code.value = (uint16_t)sorted[0];
for (key = 0; key < table_size; ++key) { for (key = 0; key < (uint32_t)table_size; ++key) {
table[key] = code; table[key] = code;
} }
return; return;
@ -175,10 +175,10 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table,
} while (++bits <= BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH); } while (++bits <= BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH);
} }
int BrotliBuildHuffmanTable(HuffmanCode* root_table, uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,
int root_bits, int root_bits,
const uint16_t* const symbol_lists, const uint16_t* const symbol_lists,
uint16_t *count) { uint16_t *count) {
HuffmanCode code; /* current table entry */ HuffmanCode code; /* current table entry */
HuffmanCode* table; /* next available space in table */ HuffmanCode* table; /* next available space in table */
int len; /* current code length */ int len; /* current code length */
@ -268,15 +268,15 @@ int BrotliBuildHuffmanTable(HuffmanCode* root_table,
step <<= 1; step <<= 1;
sub_key_step >>= 1; sub_key_step >>= 1;
} }
return total_size; return (uint32_t)total_size;
} }
int BrotliBuildSimpleHuffmanTable(HuffmanCode* table, uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode* table,
int root_bits, int root_bits,
uint16_t *val, uint16_t *val,
uint32_t num_symbols) { uint32_t num_symbols) {
int table_size = 1; uint32_t table_size = 1;
const int goal_size = 1 << root_bits; const uint32_t goal_size = 1U << root_bits;
switch (num_symbols) { switch (num_symbols) {
case 0: case 0:
table[0].bits = 0; table[0].bits = 0;
@ -362,15 +362,15 @@ int BrotliBuildSimpleHuffmanTable(HuffmanCode* table,
return goal_size; return goal_size;
} }
void BrotliHuffmanTreeGroupInit(HuffmanTreeGroup* group, int alphabet_size, void BrotliHuffmanTreeGroupInit(HuffmanTreeGroup* group, uint32_t alphabet_size,
int ntrees) { uint32_t ntrees) {
/* Pack two mallocs into one */ /* Pack two mallocs into one */
const size_t code_size = const size_t code_size =
sizeof(HuffmanCode) * (size_t)(ntrees * BROTLI_HUFFMAN_MAX_TABLE_SIZE); sizeof(HuffmanCode) * (size_t)(ntrees * BROTLI_HUFFMAN_MAX_TABLE_SIZE);
const size_t htree_size = sizeof(HuffmanCode*) * (size_t)ntrees; const size_t htree_size = sizeof(HuffmanCode*) * (size_t)ntrees;
char *p = (char*)malloc(code_size + htree_size); char *p = (char*)malloc(code_size + htree_size);
group->alphabet_size = (int16_t)alphabet_size; group->alphabet_size = (uint16_t)alphabet_size;
group->num_htrees = (int16_t)ntrees; group->num_htrees = (uint16_t)ntrees;
group->codes = (HuffmanCode*)p; group->codes = (HuffmanCode*)p;
group->htrees = (HuffmanCode**)(p + code_size); group->htrees = (HuffmanCode**)(p + code_size);
} }

View File

@ -48,30 +48,30 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* root_table,
/* Builds Huffman lookup table assuming code lengths are in symbol order. */ /* Builds Huffman lookup table assuming code lengths are in symbol order. */
/* Returns size of resulting table. */ /* Returns size of resulting table. */
int BrotliBuildHuffmanTable(HuffmanCode* root_table, uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,
int root_bits, int root_bits,
const uint16_t* const symbol_lists, const uint16_t* const symbol_lists,
uint16_t *count_arg); uint16_t *count_arg);
/* Builds a simple Huffman table. The num_symbols parameter is to be */ /* Builds a simple Huffman table. The num_symbols parameter is to be */
/* interpreted as follows: 0 means 1 symbol, 1 means 2 symbols, 2 means 3 */ /* interpreted as follows: 0 means 1 symbol, 1 means 2 symbols, 2 means 3 */
/* symbols, 3 means 4 symbols with lengths 2,2,2,2, 4 means 4 symbols with */ /* symbols, 3 means 4 symbols with lengths 2,2,2,2, 4 means 4 symbols with */
/* lengths 1,2,3,3. */ /* lengths 1,2,3,3. */
int BrotliBuildSimpleHuffmanTable(HuffmanCode* table, uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode* table,
int root_bits, int root_bits,
uint16_t *symbols, uint16_t *symbols,
uint32_t num_symbols); uint32_t num_symbols);
/* Contains a collection of Huffman trees with the same alphabet size. */ /* Contains a collection of Huffman trees with the same alphabet size. */
typedef struct { typedef struct {
HuffmanCode** htrees; HuffmanCode** htrees;
HuffmanCode* codes; HuffmanCode* codes;
int16_t alphabet_size; uint16_t alphabet_size;
int16_t num_htrees; uint16_t num_htrees;
} HuffmanTreeGroup; } HuffmanTreeGroup;
void BrotliHuffmanTreeGroupInit(HuffmanTreeGroup* group, void BrotliHuffmanTreeGroupInit(HuffmanTreeGroup* group,
int alphabet_size, int ntrees); uint32_t alphabet_size, uint32_t ntrees);
void BrotliHuffmanTreeGroupRelease(HuffmanTreeGroup* group); void BrotliHuffmanTreeGroupRelease(HuffmanTreeGroup* group);
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)

View File

@ -185,4 +185,6 @@ static BROTLI_INLINE unsigned BrotliRBit(unsigned input) {
X = NULL; \ X = NULL; \
} }
#define BROTLI_UNUSED(X) (void)(X)
#endif /* BROTLI_DEC_PORT_H_ */ #endif /* BROTLI_DEC_PORT_H_ */

View File

@ -24,7 +24,7 @@
/* [offset, offset + 2^nbits) */ /* [offset, offset + 2^nbits) */
struct PrefixCodeRange { struct PrefixCodeRange {
int16_t offset; int16_t offset;
int8_t nbits; uint8_t nbits;
}; };
static const struct PrefixCodeRange kBlockLengthPrefixCode[] = { static const struct PrefixCodeRange kBlockLengthPrefixCode[] = {

View File

@ -128,12 +128,12 @@ typedef struct {
int distance_context; int distance_context;
int meta_block_remaining_len; int meta_block_remaining_len;
int block_length[3]; int block_length[3];
int num_block_types[3]; uint32_t num_block_types[3];
int block_type_rb[6]; uint32_t block_type_rb[6];
int distance_postfix_bits; uint32_t distance_postfix_bits;
int num_direct_distance_codes; uint32_t num_direct_distance_codes;
int distance_postfix_mask; int distance_postfix_mask;
int num_dist_htrees; uint32_t num_dist_htrees;
uint8_t* dist_context_map; uint8_t* dist_context_map;
HuffmanCode *literal_htree; HuffmanCode *literal_htree;
uint8_t literal_htree_index; uint8_t literal_htree_index;
@ -171,12 +171,12 @@ typedef struct {
HuffmanCode* next; HuffmanCode* next;
/* For DecodeContextMap */ /* For DecodeContextMap */
int context_index; uint32_t context_index;
int max_run_length_prefix; uint32_t max_run_length_prefix;
HuffmanCode context_map_table[BROTLI_HUFFMAN_MAX_TABLE_SIZE]; HuffmanCode context_map_table[BROTLI_HUFFMAN_MAX_TABLE_SIZE];
/* For InverseMoveToFrontTransform */ /* For InverseMoveToFrontTransform */
int mtf_upper_bound; uint32_t mtf_upper_bound;
uint8_t mtf[256]; uint8_t mtf[256];
/* For custom dictionaries */ /* For custom dictionaries */
@ -198,7 +198,7 @@ typedef struct {
uint8_t size_nibbles; uint8_t size_nibbles;
uint32_t window_bits; uint32_t window_bits;
int num_literal_htrees; uint32_t num_literal_htrees;
uint8_t* context_map; uint8_t* context_map;
uint8_t* context_modes; uint8_t* context_modes;
} BrotliState; } BrotliState;

View File

@ -93,7 +93,9 @@ BrotliOutput BrotliFileOutput(FILE* f) {
return out; return out;
} }
int BrotliNullOutputFunction(void* data, const uint8_t* buf, size_t count) { int BrotliNullOutputFunction(void* data , const uint8_t* buf, size_t count) {
BROTLI_UNUSED(data);
BROTLI_UNUSED(buf);
return (int)count; return (int)count;
} }