Skip to content

Commit

Permalink
SDL_ConvertSurface(): add null pointer check
Browse files Browse the repository at this point in the history
Check return values of SDL_CreateSurface()
and SDL_ConvertSurface().
  • Loading branch information
szsam authored and slouken committed Apr 24, 2023
1 parent bf8c9d2 commit ac607c1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/video/SDL_surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,10 @@ SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)

/* Create a dummy surface to get the colorkey converted */
tmp = SDL_CreateSurface(1, 1, surface->format->format);
if (tmp == NULL) {
SDL_DestroySurface(convert);
return NULL;
}

/* Share the palette, if any */
if (surface->format->palette) {
Expand All @@ -1305,6 +1309,11 @@ SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)

/* Convertion of the colorkey */
tmp2 = SDL_ConvertSurface(tmp, format);
if (tmp2 == NULL) {
SDL_DestroySurface(tmp);
SDL_DestroySurface(convert);
return NULL;
}

/* Get the converted colorkey */
SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
Expand Down

0 comments on commit ac607c1

Please sign in to comment.