Don't allocate memory if we're just going to fail when checking parameters.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 20 Jul 2013 21:19:20 -0400
changeset 7487a4e43eb67e79
parent 7486 c074c0b23916
child 7488 a74f1f664047
Don't allocate memory if we're just going to fail when checking parameters.
src/render/SDL_yuv_sw.c
     1.1 --- a/src/render/SDL_yuv_sw.c	Sat Jul 20 21:10:05 2013 -0400
     1.2 +++ b/src/render/SDL_yuv_sw.c	Sat Jul 20 21:19:20 2013 -0400
     1.3 @@ -1029,12 +1029,6 @@
     1.4      int i;
     1.5      int CR, CB;
     1.6  
     1.7 -    swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
     1.8 -    if (!swdata) {
     1.9 -        SDL_OutOfMemory();
    1.10 -        return NULL;
    1.11 -    }
    1.12 -
    1.13      switch (format) {
    1.14      case SDL_PIXELFORMAT_YV12:
    1.15      case SDL_PIXELFORMAT_IYUV:
    1.16 @@ -1043,11 +1037,16 @@
    1.17      case SDL_PIXELFORMAT_YVYU:
    1.18          break;
    1.19      default:
    1.20 -        SDL_SW_DestroyYUVTexture(swdata);
    1.21          SDL_SetError("Unsupported YUV format");
    1.22          return NULL;
    1.23      }
    1.24  
    1.25 +    swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
    1.26 +    if (!swdata) {
    1.27 +        SDL_OutOfMemory();
    1.28 +        return NULL;
    1.29 +    }
    1.30 +
    1.31      swdata->format = format;
    1.32      swdata->target_format = SDL_PIXELFORMAT_UNKNOWN;
    1.33      swdata->w = w;
    1.34 @@ -1095,7 +1094,7 @@
    1.35          swdata->planes[0] = swdata->pixels;
    1.36          break;
    1.37      default:
    1.38 -        /* We should never get here (caught above) */
    1.39 +        SDL_assert(0 && "We should never get here (caught above)");
    1.40          break;
    1.41      }
    1.42