From 7c2def18f6178da4c0c6016d49a44c1552dff9f8 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 3 Apr 2026 19:02:53 +0100 Subject: [PATCH] Fix compilation in ISO C enviroments; declare vars before code. --- c/dec/decode.c | 8 ++++---- c/enc/encode.c | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/c/dec/decode.c b/c/dec/decode.c index 19c7e02..90cce9d 100644 --- a/c/dec/decode.c +++ b/c/dec/decode.c @@ -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; diff --git a/c/enc/encode.c b/c/enc/encode.c index 9e72744..b2583e4 100644 --- a/c/enc/encode.c +++ b/c/enc/encode.c @@ -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(); */