From 1a65483a219dccec92d7ac3efcb62bbd4ac0a1dd Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 6 Jul 2013 20:29:40 -0700 Subject: [PATCH] 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index d1c57119c..2544462ba 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -175,7 +175,11 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) int flags; if (!surface) { - return -1; + return SDL_InvalidParamError("surface"); + } + + if (surface->format->palette && key >= surface->format->palette->ncolors) { + return SDL_InvalidParamError("key"); } if (flag & SDL_RLEACCEL) {