prevent a 16-bit integer overflow that would create problems when rendering
*very* large anti-aliased outlines
diff --git a/ChangeLog b/ChangeLog
index b5b2fdc..2ae2699 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-06-16  David Turner  <david@freetype.org>
+
+	* src/smooth/ftgrays.c (gray_hline): prevent integer overflows
+	when rendering *very* large outlines
+
+
 2006-06-16  Dmitry Timoshkov  <dmitry@codeweavers.com>
 
 	* src/winfonts/winfnt.h: Add necessary structures for PE resource
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index 15e7ab8..9e8ee5f 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -397,6 +397,8 @@
     PCell  *pcell, cell;
     int     x = ras.ex;
 
+    if (x > ras.max_ex)
+      x = ras.max_ex;
 
     pcell = &ras.ycells[ras.ey];
     for (;;)
@@ -462,6 +464,10 @@
     /* All cells that are on the left of the clipping region go to the */
     /* min_ex - 1 horizontal position.                                 */
     ey -= ras.min_ey;
+
+    if (ex > ras.max_ex)
+      ex = ras.max_ex;
+
     ex -= ras.min_ex;
     if ( ex < 0 )
       ex = -1;
@@ -492,6 +498,9 @@
   gray_start_cell( RAS_ARG_ TCoord  ex,
                             TCoord  ey )
   {
+    if ( ex > ras.max_ex )
+      ex = (TCoord)( ras.max_ex );
+
     if ( ex < ras.min_ex )
       ex = (TCoord)( ras.min_ex - 1 );
 
@@ -1196,6 +1205,10 @@
     y += (TCoord)ras.min_ey;
     x += (TCoord)ras.min_ex;
 
+    /* FT_Span.x is a 16-bit short, so limit our coordinates appropriately */
+    if (x >= 32768)
+      x = 32767;
+
     if ( coverage )
     {
       /* see whether we can add this span to the current list */