Skip to content

Commit

Permalink
Date: Wed, 28 Jul 2004 14:56:57 +0800
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Aug 21, 2004
1 parent 40e2aa1 commit 879c3f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/video/SDL_RLEaccel.c
Expand Up @@ -1832,7 +1832,7 @@ int SDL_RLESurface(SDL_Surface *surface)
* 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;
Expand All @@ -1853,6 +1853,9 @@ static void UnRLEAlpha(SDL_Surface *surface)
}

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

Expand All @@ -1876,7 +1879,7 @@ static void UnRLEAlpha(SDL_Surface *surface)
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 */
Expand All @@ -1897,6 +1900,8 @@ static void UnRLEAlpha(SDL_Surface *surface)
} while(ofs < w);
dst += surface->pitch >> 2;
}
/* Make the compiler happy */
return(SDL_TRUE);
}

void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Expand All @@ -1912,6 +1917,11 @@ void SDL_UnRLESurface(SDL_Surface *surface, int recode)

/* 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);
Expand All @@ -1924,8 +1934,13 @@ void SDL_UnRLESurface(SDL_Surface *surface, int recode)
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 ) {
Expand Down
6 changes: 6 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -1275,10 +1275,16 @@ int SDL_SetPalette(SDL_Surface *screen, int which,
/* 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,
Expand Down

0 comments on commit 879c3f8

Please sign in to comment.