Added additional input validation to SDL_AllocPalette; added error codes; added test case to Pixels suite for coverage

This commit is contained in:
Andreas Schiffler
2013-05-04 09:11:18 -07:00
parent 7253832be1
commit 511dc6b8f0
2 changed files with 96 additions and 2 deletions

View File

@@ -503,6 +503,7 @@ SDL_AllocFormat(Uint32 pixel_format)
}
if (SDL_InitFormat(format, pixel_format) < 0) {
SDL_free(format);
SDL_InvalidParamError("format");
return NULL;
}
@@ -585,6 +586,7 @@ SDL_FreeFormat(SDL_PixelFormat *format)
SDL_PixelFormat *prev;
if (!format) {
SDL_InvalidParamError("format");
return;
}
if (--format->refcount > 0) {
@@ -613,6 +615,12 @@ SDL_Palette *
SDL_AllocPalette(int ncolors)
{
SDL_Palette *palette;
/* Input validation */
if (ncolors < 1) {
SDL_InvalidParamError("ncolors");
return NULL;
}
palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
if (!palette) {
@@ -693,6 +701,7 @@ void
SDL_FreePalette(SDL_Palette * palette)
{
if (!palette) {
SDL_InvalidParamError("palette");
return;
}
if (--palette->refcount > 0) {