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 1952 - SDL_calloc might returns NULL in SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) function
Summary: SDL_calloc might returns NULL in SDL_CreateWindow(const char *title, int x, i...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Linux
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-10 05:18 UTC by Nitz
Modified: 2013-07-11 01:14 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nitz 2013-07-10 05:18:00 UTC
In function:
SDL_Window *
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
   // Some Code

   window = (SDL_Window *)SDL_calloc(1, sizeof(*window));// In this SDL_calloc sometimes might return NULL.   

   // Some Code
}
In above function SDL_calloc sometimes might return NULL to window, which is not accepted.
So to avoid this, patch should be:

window = (SDL_Window *)SDL_calloc(1, sizeof(SDL_Window));

Thanks,
Nitz
Comment 1 Sam Lantinga 2013-07-11 01:14:46 UTC
The sizeof() is fine, but you're right that it needs to check the return value of SDL_calloc().

This is now fixed, thanks!
http://hg.libsdl.org/SDL/rev/f35ff854121a