brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {\r
BrotliDecoderState* state = 0;\r
if (!alloc_func && !free_func) {\r
- state = (BrotliDecoderState*)malloc(sizeof(BrotliDecoderState));\r
+ state = (BrotliDecoderState*)BrDummyMalloc(sizeof(BrotliDecoderState));\r
} else if (alloc_func && free_func) {\r
state = (BrotliDecoderState*)alloc_func(opaque, sizeof(BrotliDecoderState));\r
}\r
uint32_t code;\r
uint32_t nbits;\r
code = ReadSymbol(table, br);\r
+ if (code >= BROTLI_NUM_BLOCK_LEN_SYMBOLS) code = BROTLI_NUM_BLOCK_LEN_SYMBOLS - 1;\r
nbits = kBlockLengthPrefixCode[code].nbits; /* nbits == 2..24 */\r
return kBlockLengthPrefixCode[code].offset + BrotliReadBits(br, nbits);\r
}\r
uint32_t i = 4;\r
uint32_t upper_bound = state->mtf_upper_bound;\r
uint8_t* mtf = &state->mtf[4]; /* Make mtf[-1] addressable. */\r
+ uint8_t* mtft = &state->mtf[3];\r
/* Load endian-aware constant. */\r
const uint8_t b0123[4] = {0, 1, 2, 3};\r
uint32_t pattern;\r
for (i = 0; i < v_len; ++i) {\r
int index = v[i];\r
uint8_t value = mtf[index];\r
- upper_bound |= v[i];\r
+ upper_bound |= (uint32_t)v[i];\r
v[i] = value;\r
- mtf[-1] = value;\r
- do {\r
+ mtft[0] = value;\r
+ while (index >= 0) {\r
+ mtft[index + 1] = mtft[index];\r
index--;\r
- mtf[index + 1] = mtf[index];\r
- } while (index >= 0);\r
+ }\r
}\r
/* Remember amount of elements to be reinitialized. */\r
state->mtf_upper_bound = upper_bound;\r
return BROTLI_FALSE;\r
}\r
}\r
+ if (cmd_code >= BROTLI_NUM_COMMAND_SYMBOLS) cmd_code = BROTLI_NUM_COMMAND_SYMBOLS - 1;\r
v = kCmdLut[cmd_code];\r
s->distance_code = v.distance_code;\r
s->distance_context = v.context;\r
}\r
s->max_distance = s->max_backward_distance;\r
if (s->state == BROTLI_STATE_COMMAND_POST_WRITE_1) {\r
- memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)s->pos);\r
+ if (s->ringbuffer != 0) {\r
+ memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)s->pos);\r
+ }\r
if (s->meta_block_remaining_len == 0) {\r
/* Next metablock, if any */\r
s->state = BROTLI_STATE_METABLOCK_DONE;\r