forbid GFX2_Surfaces with 0 pixels

This commit is contained in:
Thomas Bernard
2018-06-25 17:05:43 +02:00
parent 01c6a9cd09
commit 32f6cbfb5c
2 changed files with 15 additions and 12 deletions

View File

@@ -28,22 +28,18 @@ T_GFX2_Surface * New_GFX2_Surface(word width, word height)
T_GFX2_Surface * surface;
size_t size;
size = width * height;
if (size == 0) // surfaces with no pixels not allowed
return NULL;
surface = malloc(sizeof(T_GFX2_Surface));
if (surface == NULL)
return NULL;
size = width * height;
if (size > 0)
surface->pixels = malloc(size);
if(surface->pixels == NULL)
{
surface->pixels = malloc(size);
if(surface->pixels == NULL)
{
free(surface);
return NULL;
}
}
else
{
surface->pixels = NULL;
free(surface);
return NULL;
}
memset(surface->palette, 0, sizeof(surface->palette));
surface->w = width;