Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Don't allocate memory if we're just going to fail when checking param…
Browse files Browse the repository at this point in the history
…eters.
  • Loading branch information
icculus committed Jul 21, 2013
1 parent 3fc8f71 commit 721a420
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/render/SDL_yuv_sw.c
Expand Up @@ -1029,12 +1029,6 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
int i;
int CR, CB;

swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
if (!swdata) {
SDL_OutOfMemory();
return NULL;
}

switch (format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
Expand All @@ -1043,11 +1037,16 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
case SDL_PIXELFORMAT_YVYU:
break;
default:
SDL_SW_DestroyYUVTexture(swdata);
SDL_SetError("Unsupported YUV format");
return NULL;
}

swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
if (!swdata) {
SDL_OutOfMemory();
return NULL;
}

swdata->format = format;
swdata->target_format = SDL_PIXELFORMAT_UNKNOWN;
swdata->w = w;
Expand Down Expand Up @@ -1095,7 +1094,7 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
swdata->planes[0] = swdata->pixels;
break;
default:
/* We should never get here (caught above) */
SDL_assert(0 && "We should never get here (caught above)");
break;
}

Expand Down

0 comments on commit 721a420

Please sign in to comment.