Properly signed math in SDL fillrect clipping; fixes a crash when filling fuel tanks over 10; bug #1082

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3529 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2010-02-12 00:20:25 +00:00
parent 1df8a12111
commit 51c4e84b20
2 changed files with 14 additions and 7 deletions
+13 -7
View File
@@ -466,33 +466,39 @@ clip_rect(SDL_Rect *r, const SDL_Rect *clip_r)
// NOTE: the following clipping code is copied in part
// from SDL-1.2.4 sources
int dx, dy;
int w = r->w;
int h = r->h;
// SDL_Rect.w and .h are unsigned, we need signed
dx = clip_r->x - r->x;
if (dx > 0)
{
r->w -= dx;
w -= dx;
r->x += dx;
}
dx = r->x + r->w - clip_r->x - clip_r->w;
dx = r->x + w - clip_r->x - clip_r->w;
if (dx > 0)
r->w -= dx;
w -= dx;
dy = clip_r->y - r->y;
if (dy > 0)
{
r->h -= dy;
h -= dy;
r->y += dy;
}
dy = r->y + r->h - clip_r->y - clip_r->h;
dy = r->y + h - clip_r->y - clip_r->h;
if (dy > 0)
r->h -= dy;
h -= dy;
if (r->w <= 0 || r->h <= 0)
if (w <= 0 || h <= 0)
{
r->w = 0;
r->h = 0;
return 0;
}
r->w = w;
r->h = h;
return 1;
}