From c3bfc83689421d571635191ce804af5cffc881db Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 13 Oct 2023 07:00:25 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20Se=20corrompia=20la=20mem=C3=B2ria?= =?UTF-8?q?=20al=20no=20reservar=20la=20quantitat=20sufucient.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/gif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/gif.c b/source/gif.c index 66a63cc..7c73f11 100644 --- a/source/gif.c +++ b/source/gif.c @@ -334,8 +334,7 @@ unsigned char* process_image_descriptor( unsigned char* buffer, */ #define rb (*(buffer++)) -uint32_t* LoadPalette(unsigned char *b, int *paletteSize = NULL) { - unsigned char *buffer = b; +uint32_t* LoadPalette(unsigned char *buffer, int *paletteSize = NULL) { unsigned char header[7]; screen_descriptor_t screen_descriptor; //int color_resolution_bits; @@ -349,10 +348,12 @@ uint32_t* LoadPalette(unsigned char *b, int *paletteSize = NULL) { //color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1; //global_color_table = (uint32_t *)calloc(1, 1024); - if (screen_descriptor.fields & 0x80) { + if (screen_descriptor.fields & 0x80) + { global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1)); + if (paletteSize != NULL) *paletteSize = global_color_table_size; - global_color_table = (uint32_t *)malloc(3 * global_color_table_size); + global_color_table = (uint32_t *)malloc(4 * global_color_table_size); //READ(global_color_table, 3 * global_color_table_size); for (int i=0; i