We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2681

Summary: dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function
Product: SDL Reporter: Nitz <nitin.j4>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2    
Version: 2.0.3   
Hardware: x86   
OS: Linux   
Attachments: patch

Description Nitz 2014-08-12 05:28:38 UTC
Created attachment 1812 [details]
patch

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);

so it should be like that:

        SDL_PixelFormat *dst_fmt;
        SDL_Surface *temp = NULL;

        /* Set up a destination surface for the texture update */
        dst_fmt = SDL_AllocFormat(format);
        if (!dst_fmt) {
            SDL_DestroyTexture(texture);
            return NULL;
        }

        temp = SDL_ConvertSurface(surface, dst_fmt, 0);
        SDL_FreeFormat(dst_fmt);


Thanks!!!
Comment 1 Sam Lantinga 2014-08-17 06:31:06 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/230e7558f76a