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

Commit

Permalink
Added input parameter validation to some SDL_rect functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ferzkopp committed Sep 5, 2011
1 parent 70d2c64 commit bb03617
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/video/SDL_rect.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bb03617

Please sign in to comment.