Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added input parameter validation to some SDL_rect functions

  • Loading branch information
ferzkopp committed Sep 5, 2011
1 parent 70d2c64 commit bb03617d1df10de0e56a6ab50bb4308e2470fe11
Showing with 36 additions and 0 deletions.
  1. +36 −0 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;

0 comments on commit bb03617

Please sign in to comment.