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 - dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function
Summary: dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.3
Hardware: x86 Linux
: P2 critical
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-12 05:28 UTC by Nitz
Modified: 2014-08-17 06:31 UTC (History)
0 users

See Also:


Attachments
patch (480 bytes, text/plain)
2014-08-12 05:28 UTC, Nitz
Details

Note You need to log in before you can comment on or make changes to this bug.
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