Fixed some possible malloc(0) calls reported by static analysis.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 24 Jun 2018 12:16:58 -0400
changeset 1202783df3afcf475
parent 12025 39a92b19f99e
child 12028 8aa5a79c8805
Fixed some possible malloc(0) calls reported by static analysis.
src/render/opengles2/SDL_render_gles2.c
     1.1 --- a/src/render/opengles2/SDL_render_gles2.c	Mon Jun 18 13:14:04 2018 -0700
     1.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sun Jun 24 12:16:58 2018 -0400
     1.3 @@ -719,6 +719,10 @@
     1.4      int src_pitch;
     1.5      int y;
     1.6  
     1.7 +    if ((width == 0) || (height == 0) || (bpp == 0)) {
     1.8 +        return;  /* nothing to do */
     1.9 +    }
    1.10 +
    1.11      /* Reformat the texture data into a tightly packed array */
    1.12      src_pitch = width * bpp;
    1.13      src = (Uint8 *)pixels;
    1.14 @@ -1928,6 +1932,7 @@
    1.15  {
    1.16      GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
    1.17      Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
    1.18 +    size_t buflen;
    1.19      void *temp_pixels;
    1.20      int temp_pitch;
    1.21      Uint8 *src, *dst, *tmp;
    1.22 @@ -1937,7 +1942,12 @@
    1.23      GLES2_ActivateRenderer(renderer);
    1.24  
    1.25      temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
    1.26 -    temp_pixels = SDL_malloc(rect->h * temp_pitch);
    1.27 +    buflen = (size_t) (rect->h * temp_pitch);
    1.28 +    if (buflen == 0) {
    1.29 +        return 0;  /* nothing to do. */
    1.30 +    }
    1.31 +
    1.32 +    temp_pixels = SDL_malloc(buflen);
    1.33      if (!temp_pixels) {
    1.34          return SDL_OutOfMemory();
    1.35      }