Fixed bug 2681 - dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function
authorSam Lantinga <slouken@libsdl.org>
Sat, 16 Aug 2014 23:30:44 -0700
changeset 9078230e7558f76a
parent 9077 28e6de55eb07
child 9079 373df87521e5
Fixed bug 2681 - dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function

Nitz

In SDL_CreateTextureFromSurface:

SDL_PixelFormat *dst_fmt;
/* Set up a destination surface for the texture update */
dst_fmt = SDL_AllocFormat(format);
temp = SDL_ConvertSurface(surface, dst_fmt, 0);

Here is need of NULL check for dst_fmt because there are chances of NULL return from SDL_AllocFormat(format);
src/render/SDL_render.c
     1.1 --- a/src/render/SDL_render.c	Sat Aug 16 23:28:40 2014 -0700
     1.2 +++ b/src/render/SDL_render.c	Sat Aug 16 23:30:44 2014 -0700
     1.3 @@ -540,6 +540,10 @@
     1.4  
     1.5          /* Set up a destination surface for the texture update */
     1.6          dst_fmt = SDL_AllocFormat(format);
     1.7 +        if (!dst_fmt) {
     1.8 +           SDL_DestroyTexture(texture);
     1.9 +           return NULL;
    1.10 +        }
    1.11          temp = SDL_ConvertSurface(surface, dst_fmt, 0);
    1.12          SDL_FreeFormat(dst_fmt);
    1.13          if (temp) {