From 15eed4cdc2263e42c48b1550b435e3583807e6cf Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sun, 4 Sep 2011 20:34:48 -0700 Subject: [PATCH] Added input parameter validation to some SDL_rect functions --- src/video/SDL_rect.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/video/SDL_rect.c b/src/video/SDL_rect.c index 7ae99affd..d47fe109d 100644 --- a/src/video/SDL_rect.c +++ b/src/video/SDL_rect.c @@ -28,6 +28,11 @@ SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B) { int Amin, Amax, Bmin, Bmax; + if (!A || !B) { + // TODO error message + return SDL_FALSE; + } + /* Horizontal intersection */ Amin = A->x; Amax = Amin + A->w; @@ -60,6 +65,11 @@ SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) { int Amin, Amax, Bmin, Bmax; + if (!A || !B || !result) { + // TODO error message + return SDL_FALSE; + } + /* Horizontal intersection */ Amin = A->x; Amax = Amin + A->w; @@ -92,6 +102,10 @@ SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) { int Amin, Amax, Bmin, Bmax; + if (!A || !B || !result) { + return; + } + /* Horizontal union */ Amin = A->x; Amax = Amin + A->w; @@ -127,7 +141,13 @@ SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip, int maxy = 0; int x, y, i; + if (!points || !clip) { + // TODO error message + return SDL_FALSE; + } + if (count < 1) { + // TODO error message return SDL_FALSE; } @@ -234,6 +254,7 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, int outcode1, outcode2; if (!rect || !X1 || !Y1 || !X2 || !Y2) { + // TODO error message return SDL_FALSE; } @@ -347,6 +368,21 @@ SDL_GetSpanEnclosingRect(int width, int height, int span_y1, span_y2; int rect_y1, rect_y2; + if (width < 1 || height < 1) { + // TODO error message + return SDL_FALSE; + } + + if (!rects || !span) { + // TODO error message + return SDL_FALSE; + } + + if (numrects < 1) { + // TODO error message + return SDL_FALSE; + } + /* Initialize to empty rect */ span_y1 = height; span_y2 = 0;