aboutsummaryrefslogtreecommitdiff
path: root/dw/fltkviewbase.cc
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2011-02-25 22:55:22 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2011-02-25 22:55:22 +0100
commit6ffc8889889552c91ff3454129ff478a564a2a4b (patch)
treeb68113199c226c6cced68e7c95507c044a8a8a7c /dw/fltkviewbase.cc
parent5838110e47126a30eb13f9d7da5c1ef11321fe26 (diff)
minimize draw rect before passing it to fl_clip_box to avoid overflows
fl_clip_box() uses X11 calls internally that use shorts, so big values can overflow. Reported by: corvid <corvid@lavabit.com>
Diffstat (limited to 'dw/fltkviewbase.cc')
-rw-r--r--dw/fltkviewbase.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc
index 02494fff..d14f866c 100644
--- a/dw/fltkviewbase.cc
+++ b/dw/fltkviewbase.cc
@@ -134,13 +134,18 @@ void FltkViewBase::draw ()
void FltkViewBase::draw (const core::Rectangle *rect,
DrawType type)
{
- int X, Y, W, H;
+ int X = translateCanvasXToViewX (rect->x);
+ int Y = translateCanvasYToViewY (rect->y);
+ int W, H;
+
+ // fl_clip_box() can't handle values greater than SHRT_MAX!
+ if (X > x () + w () || Y > y () + h ())
+ return;
- fl_clip_box(translateCanvasXToViewX (rect->x),
- translateCanvasYToViewY (rect->y),
- rect->width,
- rect->height,
- X, Y, W, H);
+ W = X + rect->width > x () + w () ? x () + w () - X : rect->width;
+ H = Y + rect->height > y () + h () ? y () + h () - Y : rect->height;
+
+ fl_clip_box(X, Y, W, H, X, Y, W, H);
core::Rectangle r (translateViewXToCanvasX (X),
translateViewYToCanvasY (Y), W, H);