From 51c4e84b20dc7c02ed35c01d93e2a19376c92e60 Mon Sep 17 00:00:00 2001 From: avolkov Date: Fri, 12 Feb 2010 00:20:25 +0000 Subject: [PATCH] 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 --- sc2/ChangeLog | 1 + sc2/src/libs/graphics/sdl/primitives.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 3b19270df..527c15a7f 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Fixed a crash when filling fuel tanks over 10 (bug #1082) - Alex - Got rid of many warnings - SvdB - Clean up and some refactoring of the SuperMelee code - SvdB - Fixed concurrent screen fades regression (bug #1079) - Alex diff --git a/sc2/src/libs/graphics/sdl/primitives.c b/sc2/src/libs/graphics/sdl/primitives.c index edebb419b..3cf16b49a 100644 --- a/sc2/src/libs/graphics/sdl/primitives.c +++ b/sc2/src/libs/graphics/sdl/primitives.c @@ -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; }