Fixed potential overflow in surface allocation (thanks Yves!)
This commit is contained in:
parent
be62ae8910
commit
64786b5dfc
1 changed files with 9 additions and 1 deletions
|
@ -80,7 +80,15 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
|
||||||
|
|
||||||
/* Get the pixels */
|
/* Get the pixels */
|
||||||
if (surface->w && surface->h) {
|
if (surface->w && surface->h) {
|
||||||
surface->pixels = SDL_malloc(surface->h * surface->pitch);
|
int size = (surface->h * surface->pitch);
|
||||||
|
if (size < 0 || (size / surface->pitch) != surface->h) {
|
||||||
|
/* Overflow... */
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
surface->pixels = SDL_malloc(size);
|
||||||
if (!surface->pixels) {
|
if (!surface->pixels) {
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue