Fixed all known static analysis bugs, with checker-279 on macOS.

This commit is contained in:
Ryan C. Gordon
2016-11-24 21:41:09 -05:00
parent fd250bd636
commit fb5fd67ccb
8 changed files with 159 additions and 88 deletions

View File

@@ -1277,7 +1277,7 @@ RLEColorkeySurface(SDL_Surface * surface)
int y;
Uint8 *srcbuf, *lastline;
int maxsize = 0;
int bpp = surface->format->BytesPerPixel;
const int bpp = surface->format->BytesPerPixel;
getpix_func getpix;
Uint32 ckey, rgbmask;
int w, h;
@@ -1300,6 +1300,9 @@ RLEColorkeySurface(SDL_Surface * surface)
maxsize = surface->h * (4 * (surface->w / 65535 + 1)
+ surface->w * 4) + 4;
break;
default:
return -1;
}
rlebuf = (Uint8 *) SDL_malloc(maxsize);
@@ -1393,7 +1396,7 @@ RLEColorkeySurface(SDL_Surface * surface)
surface->map->data = p;
}
return (0);
return 0;
}
int

View File

@@ -22,7 +22,7 @@
#include "SDL_rect.h"
#include "SDL_rect_c.h"
#include "SDL_assert.h"
SDL_bool
SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B)
@@ -441,9 +441,15 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
y = recty2;
x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
} else if (outcode2 & CODE_LEFT) {
/* If this assertion ever fires, here's the static analysis that warned about it:
http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-b0d01a.html#EndPath */
SDL_assert(x2 != x1); /* if equal: division by zero. */
x = rectx1;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
} else if (outcode2 & CODE_RIGHT) {
/* If this assertion ever fires, here's the static analysis that warned about it:
http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-39b114.html#EndPath */
SDL_assert(x2 != x1); /* if equal: division by zero. */
x = rectx2;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
}

View File

@@ -338,9 +338,14 @@ SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * f
/* Create framebuffer data */
data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format);
data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3);
data->pixels = SDL_malloc(window->h * data->pitch);
if (!data->pixels) {
return SDL_OutOfMemory();
{
/* Make static analysis happy about potential malloc(0) calls. */
const size_t allocsize = window->h * data->pitch;
data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
if (!data->pixels) {
return SDL_OutOfMemory();
}
}
*pixels = data->pixels;