Skip to content

Commit

Permalink
Don't crash creating non-paletted surfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 21, 2019
1 parent 3bdaee9 commit 9c5855e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/SDL12_compat.c
Expand Up @@ -1930,17 +1930,22 @@ Surface20to12(SDL_Surface *surface20)
if (!surface12)
goto failed;

palette12 = (SDL12_Palette *) SDL20_malloc(sizeof (SDL12_Palette));
if (!palette12)
goto failed;
if (surface20->format->palette) {
palette12 = (SDL12_Palette *) SDL20_malloc(sizeof (SDL12_Palette));
if (!palette12)
goto failed;
}

format12 = (SDL12_PixelFormat *) SDL20_malloc(sizeof (SDL12_PixelFormat));
if (!format12)
goto failed;

SDL20_zerop(palette12);
palette12->ncolors = surface20->format->palette->ncolors;
palette12->colors = surface20->format->palette->colors;
if (palette12) {
SDL20_zerop(palette12);
SDL_assert(surface20->format->palette);
palette12->ncolors = surface20->format->palette->ncolors;
palette12->colors = surface20->format->palette->colors;
}

SDL20_zerop(format12);
format12->palette = palette12;
Expand Down

0 comments on commit 9c5855e

Please sign in to comment.