- [FIX] Se corrompia la memòria al no reservar la quantitat sufucient.

This commit is contained in:
2023-10-13 07:00:25 +02:00
parent e8a5c033bb
commit c3bfc83689

View File

@@ -334,8 +334,7 @@ unsigned char* process_image_descriptor( unsigned char* buffer,
*/ */
#define rb (*(buffer++)) #define rb (*(buffer++))
uint32_t* LoadPalette(unsigned char *b, int *paletteSize = NULL) { uint32_t* LoadPalette(unsigned char *buffer, int *paletteSize = NULL) {
unsigned char *buffer = b;
unsigned char header[7]; unsigned char header[7];
screen_descriptor_t screen_descriptor; screen_descriptor_t screen_descriptor;
//int color_resolution_bits; //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; //color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
//global_color_table = (uint32_t *)calloc(1, 1024); //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)); global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
if (paletteSize != NULL) *paletteSize = global_color_table_size; 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); //READ(global_color_table, 3 * global_color_table_size);
for (int i=0; i<global_color_table_size;++i) { for (int i=0; i<global_color_table_size;++i) {
global_color_table[i] = (buffer[0]<<16) + (buffer[1]<<8) + buffer[2]; global_color_table[i] = (buffer[0]<<16) + (buffer[1]<<8) + buffer[2];