Fixed bug 1923 - Crash with SDL_SetColorKey
authorSam Lantinga <slouken@libsdl.org>
Sat, 06 Jul 2013 20:29:40 -0700
changeset 736375b8a207cb65
parent 7362 fdf6c14b447c
child 7364 e21bd6987b86
Fixed bug 1923 - Crash with SDL_SetColorKey

Sylvain

1/ Load an Image XPM with IMG_ReadXPMFromArray()
2/ Try to set a ColorKey on it.

I notice that :
- the SDL_Surface that is created from XPM has a palette !
- the colorkey is a RBG.

it crashes (SIGSEGV) inside the SDL_SetColorKey function:
"surface->format->palette->colors[surface->map->info.colorkey].a"
src/video/SDL_surface.c
     1.1 --- a/src/video/SDL_surface.c	Sat Jul 06 12:39:56 2013 -0700
     1.2 +++ b/src/video/SDL_surface.c	Sat Jul 06 20:29:40 2013 -0700
     1.3 @@ -175,7 +175,11 @@
     1.4      int flags;
     1.5  
     1.6      if (!surface) {
     1.7 -        return -1;
     1.8 +        return SDL_InvalidParamError("surface");
     1.9 +    }
    1.10 +
    1.11 +    if (surface->format->palette && key >= surface->format->palette->ncolors) {
    1.12 +        return SDL_InvalidParamError("key");
    1.13      }
    1.14  
    1.15      if (flag & SDL_RLEACCEL) {