From a7cbdea4c54d2a0eab22128670b35f343b04610f Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 24 Nov 2025 14:30:11 +0100 Subject: [PATCH] - [FIX] uncompress() cleanup --- gif.h | 39 +++++++++++++-------------------------- version.h | 2 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/gif.h b/gif.h index e7dc897..0684bab 100644 --- a/gif.h +++ b/gif.h @@ -22,19 +22,12 @@ struct dictionary_entry_t void uncompress( int code_length, const uint8_t *input, int input_length, uint8_t *out ) { - int i, bit; - int code, prev = -1; dictionary_entry_t *dictionary; int dictionary_ind; - uint32_t mask = 0x01; - int reset_code_length; - int clear_code; // This varies depending on code_length - int stop_code; // one more than clear code - int match_len; - clear_code = 1 << ( code_length ); - stop_code = clear_code + 1; - reset_code_length = code_length; + const int clear_code = 1 << ( code_length ); + const int stop_code = clear_code + 1; + const int reset_code_length = code_length; dictionary = ( dictionary_entry_t * ) malloc( sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) ); @@ -47,12 +40,15 @@ void uncompress( int code_length, const uint8_t *input, int input_length, uint8_ } dictionary_ind+=2; + int prev = -1; + uint32_t mask = 0x01; while ( input_length ) { - code = 0x0; - for (i=0; i<(code_length + 1); i++) + int code = 0x0; + + for (int i=0; i<(code_length + 1); i++) { - bit = ( *input & mask ) ? 1 : 0; + const int bit = ( *input & mask ) ? 1 : 0; mask <<= 1; if ( mask == 0x100 ) @@ -90,18 +86,9 @@ void uncompress( int code_length, const uint8_t *input, int input_length, uint8_ exit( 0 ); } - if ( code == dictionary_ind ) - { - int ptr = prev; - while ( dictionary[ ptr ].prev != -1 ) ptr = dictionary[ ptr ].prev; - dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte; - } - else - { - int ptr = code; - while ( dictionary[ ptr ].prev != -1 ) ptr = dictionary[ ptr ].prev; - dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte; - } + int ptr = (code == dictionary_ind) ? prev : code; + while ( dictionary[ ptr ].prev != -1 ) ptr = dictionary[ ptr ].prev; + dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte; dictionary[ dictionary_ind ].prev = prev; dictionary[ dictionary_ind ].len = dictionary[ prev ].len + 1; @@ -116,7 +103,7 @@ void uncompress( int code_length, const uint8_t *input, int input_length, uint8_ prev = code; - match_len = dictionary[ code ].len; + const int match_len = dictionary[ code ].len; while ( code != -1 ) { out[ dictionary[ code ].len - 1 ] = dictionary[ code ].byte; diff --git a/version.h b/version.h index 138716e..6f5ea14 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.3.10" +#define MINI_VERSION "1.3.11"