Llevats un parell de warnings en pLoadSurface i pLoadPal

This commit is contained in:
2025-03-02 09:39:48 +01:00
parent b1ba5e67dc
commit 82f0992116

View File

@@ -82,21 +82,44 @@ jSurface pLoadSurface(const char *filename)
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
long size = ftell(f); long size = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
Uint8 *buffer = (Uint8 *)malloc(size); Uint8 *buffer = (Uint8 *)malloc(size);
fread(buffer, size, 1, f); if (!buffer) // Verificar que la memoria se asignó correctamente
{
fclose(f);
return NULL;
}
// Verificar el retorno de fread
if (fread(buffer, size, 1, f) != 1)
{
free(buffer); // Liberar memoria si falla la lectura
fclose(f);
return NULL;
}
fclose(f); fclose(f);
Uint16 w, h; Uint16 w, h;
Uint8 *pixels = LoadGif(buffer, &w, &h); Uint8 *pixels = LoadGif(buffer, &w, &h);
free(buffer); // Liberar memoria después de usar el buffer
if (pixels == NULL) if (pixels == NULL)
{ {
return NULL; return NULL;
} }
jSurface surf = (jSurface)malloc(sizeof(jSurface_s)); jSurface surf = (jSurface)malloc(sizeof(jSurface_s));
if (!surf) // Verificar que la memoria se asignó correctamente
{
free(pixels); // Liberar los píxeles si falla
return NULL;
}
surf->w = w; surf->w = w;
surf->h = h; surf->h = h;
surf->data = pixels; surf->data = pixels;
free(buffer);
return surf; return surf;
} }
@@ -110,15 +133,30 @@ void pLoadPal(const char *filename)
long size = ftell(f); long size = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
Uint8 *buffer = (Uint8 *)malloc(size); Uint8 *buffer = (Uint8 *)malloc(size);
fread(buffer, size, 1, f); if (!buffer) // Verificar que la asignación de memoria fue exitosa
{
fclose(f);
return;
}
// Verificar el resultado de fread
if (fread(buffer, size, 1, f) != 1)
{
free(buffer); // Liberar memoria si falla la lectura
fclose(f);
return;
}
fclose(f); fclose(f);
Uint32 *pal = LoadPalette(buffer); Uint32 *pal = LoadPalette(buffer);
free(buffer); // Liberar memoria después de usar el buffer
if (pal == NULL) if (pal == NULL)
{ {
return; return;
} }
free(buffer);
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)
{ {
paleta[i] = pal[i]; paleta[i] = pal[i];