Mercurial > sdl-ios-xcode
changeset 944:cdea7cbc3e23
Date: Wed, 28 Jul 2004 14:56:57 +0800
From: Aaron Perez
Subject: [SDL] Fwd: SDL not checking malloc returning NULL
I was reading through the code and i found that in several places does a
malloc and without checking if it is NULL just use the pointer.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 21 Aug 2004 13:10:58 +0000 |
parents | 715c32d8f26c |
children | d33645c36072 |
files | src/video/SDL_RLEaccel.c src/video/SDL_video.c |
diffstat | 2 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/SDL_RLEaccel.c Sat Aug 21 12:38:50 2004 +0000 +++ b/src/video/SDL_RLEaccel.c Sat Aug 21 13:10:58 2004 +0000 @@ -1832,7 +1832,7 @@ * completely transparent pixels will be lost, and colour and alpha depth * may have been reduced (when encoding for 16bpp targets). */ -static void UnRLEAlpha(SDL_Surface *surface) +static SDL_bool UnRLEAlpha(SDL_Surface *surface) { Uint8 *srcbuf; Uint32 *dst; @@ -1853,6 +1853,9 @@ } surface->pixels = malloc(surface->h * surface->pitch); + if ( !surface->pixels ) { + return(SDL_FALSE); + } /* fill background with transparent pixels */ memset(surface->pixels, 0, surface->h * surface->pitch); @@ -1876,7 +1879,7 @@ srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf); ofs += run; } else if(!ofs) - return; + return(SDL_TRUE); } while(ofs < w); /* skip padding if needed */ @@ -1897,6 +1900,8 @@ } while(ofs < w); dst += surface->pitch >> 2; } + /* Make the compiler happy */ + return(SDL_TRUE); } void SDL_UnRLESurface(SDL_Surface *surface, int recode) @@ -1912,6 +1917,11 @@ /* re-create the original surface */ surface->pixels = malloc(surface->h * surface->pitch); + if ( !surface->pixels ) { + /* Oh crap... */ + surface->flags |= SDL_RLEACCEL; + return; + } /* fill it with the background colour */ SDL_FillRect(surface, NULL, surface->format->colorkey); @@ -1924,8 +1934,13 @@ surface->flags &= ~SDL_SRCALPHA; /* opaque blit */ SDL_RLEBlit(surface, &full, surface, &full); surface->flags |= alpha_flag; - } else - UnRLEAlpha(surface); + } else { + if ( !UnRLEAlpha(surface) ) { + /* Oh crap... */ + surface->flags |= SDL_RLEACCEL; + return; + } + } } if ( surface->map && surface->map->sw_data->aux_data ) {
--- a/src/video/SDL_video.c Sat Aug 21 12:38:50 2004 +0000 +++ b/src/video/SDL_video.c Sat Aug 21 13:10:58 2004 +0000 @@ -1275,10 +1275,16 @@ /* Lazy physical palette allocation */ int size; SDL_Palette *pp = malloc(sizeof(*pp)); + if ( !pp ) { + return 0; + } current_video->physpal = pp; pp->ncolors = pal->ncolors; size = pp->ncolors * sizeof(SDL_Color); pp->colors = malloc(size); + if ( !pp->colors ) { + return 0; + } memcpy(pp->colors, pal->colors, size); } if ( ! SetPalette_physical(screen,