Fix compilation in ISO C enviroments; declare vars before code.

This commit is contained in:
Robin Watts
2026-04-03 19:02:53 +01:00
parent 5583858f76
commit 7c2def18f6
2 changed files with 6 additions and 5 deletions

View File

@@ -481,6 +481,9 @@ static BROTLI_INLINE int BrotliCopyPreloadedSymbolsToU8(const HuffmanCode* table
uint8_t* ringbuffer,
int pos,
const int limit) {
const int kMaximalOverread = 4;
int pos_limit = limit;
int copies = 0;
/* Calculate range where CheckInputAmount is always true.
Start with the number of bytes we can read. */
int64_t new_lim = br->guard_in - br->next_in;
@@ -488,9 +491,6 @@ static BROTLI_INLINE int BrotliCopyPreloadedSymbolsToU8(const HuffmanCode* table
new_lim *= 8;
/* At most 15 bits per symbol, so this is safe. */
new_lim /= 15;
const int kMaximalOverread = 4;
int pos_limit = limit;
int copies = 0;
if ((new_lim - kMaximalOverread) <= limit) {
// Safe cast, since new_lim is already < num_steps
pos_limit = (int)(new_lim - kMaximalOverread);
@@ -2086,10 +2086,10 @@ CommandInner:
} while (--i != 0);
} else { /* safe */
do {
brotli_reg_t literal;
if (BROTLI_PREDICT_FALSE(s->block_length[0] == 0)) {
goto NextLiteralBlock;
}
brotli_reg_t literal;
if (!SafeReadSymbol(s->literal_htree, br, &literal)) {
result = BROTLI_DECODER_NEEDS_MORE_INPUT;
goto saveStateAndReturn;

View File

@@ -761,11 +761,12 @@ static void BrotliEncoderInitState(BrotliEncoderState* s) {
BrotliEncoderState* BrotliEncoderCreateInstance(
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
BrotliEncoderState* state;
BROTLI_BOOL healthy = BrotliEncoderEnsureStaticInit();
if (!healthy) {
return 0;
}
BrotliEncoderState* state = (BrotliEncoderState*)BrotliBootstrapAlloc(
state = (BrotliEncoderState*)BrotliBootstrapAlloc(
sizeof(BrotliEncoderState), alloc_func, free_func, opaque);
if (state == NULL) {
/* BROTLI_DUMP(); */