Huw Davies : gdi32: Don' t update the bounds if any poly{line|gon} has fewer than two points.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Mar 9 08:05:56 CST 2016


Module: wine
Branch: master
Commit: 6e05189ba44d2e06bd49f4bced386a1e8d05a378
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6e05189ba44d2e06bd49f4bced386a1e8d05a378

Author: Huw Davies <huw at codeweavers.com>
Date:   Wed Mar  9 11:17:04 2016 +0000

gdi32: Don't update the bounds if any poly{line|gon} has fewer than two points.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/enhmfdrv/graphics.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/dlls/gdi32/enhmfdrv/graphics.c b/dlls/gdi32/enhmfdrv/graphics.c
index 83f822a..d3b3325 100644
--- a/dlls/gdi32/enhmfdrv/graphics.c
+++ b/dlls/gdi32/enhmfdrv/graphics.c
@@ -484,28 +484,33 @@ EMFDRV_PolyPolylinegon( PHYSDEV dev, const POINT* pt, const INT* counts, UINT po
     EMRPOLYPOLYLINE *emr;
     DWORD cptl = 0, poly, size, i;
     INT point;
-    RECTL bounds;
+    const RECTL empty = {0, 0, -1, -1};
+    RECTL bounds = empty;
     const POINT *pts;
-    BOOL ret, use_small_emr = TRUE;
-
-    bounds.left = bounds.right = pt[0].x;
-    bounds.top = bounds.bottom = pt[0].y;
+    BOOL ret, use_small_emr = TRUE, bounds_valid = TRUE;
 
     pts = pt;
     for(poly = 0; poly < polys; poly++) {
         cptl += counts[poly];
+        if(counts[poly] < 2) bounds_valid = FALSE;
 	for(point = 0; point < counts[poly]; point++) {
             /* check whether all points fit in the SHORT int POINT structure */
             if( ((pts->x+0x8000) & ~0xffff ) ||
                 ((pts->y+0x8000) & ~0xffff ) )
                 use_small_emr = FALSE;
-	    if(bounds.left > pts->x) bounds.left = pts->x;
-	    else if(bounds.right < pts->x) bounds.right = pts->x;
-	    if(bounds.top > pts->y) bounds.top = pts->y;
-	    else if(bounds.bottom < pts->y) bounds.bottom = pts->y;
+            if(pts == pt) {
+                bounds.left = bounds.right = pts->x;
+                bounds.top = bounds.bottom = pts->y;
+            } else {
+                if(bounds.left > pts->x) bounds.left = pts->x;
+                else if(bounds.right < pts->x) bounds.right = pts->x;
+                if(bounds.top > pts->y) bounds.top = pts->y;
+                else if(bounds.bottom < pts->y) bounds.bottom = pts->y;
+            }
 	    pts++;
 	}
     }
+    if(!cptl) bounds_valid = FALSE;
 
     size = FIELD_OFFSET(EMRPOLYPOLYLINE, aPolyCounts[polys]);
     if(use_small_emr)
@@ -519,7 +524,10 @@ EMFDRV_PolyPolylinegon( PHYSDEV dev, const POINT* pt, const INT* counts, UINT po
     if(use_small_emr) emr->emr.iType += EMR_POLYPOLYLINE16 - EMR_POLYPOLYLINE;
 
     emr->emr.nSize = size;
-    emr->rclBounds = bounds;
+    if(bounds_valid)
+        emr->rclBounds = bounds;
+    else
+        emr->rclBounds = empty;
     emr->nPolys = polys;
     emr->cptl = cptl;
 
@@ -543,6 +551,11 @@ EMFDRV_PolyPolylinegon( PHYSDEV dev, const POINT* pt, const INT* counts, UINT po
     }
 
     ret = EMFDRV_WriteRecord( dev, &emr->emr );
+    if(ret && !bounds_valid)
+    {
+        ret = FALSE;
+        SetLastError( ERROR_INVALID_PARAMETER );
+    }
     if(ret)
         EMFDRV_UpdateBBox( dev, &emr->rclBounds );
     HeapFree( GetProcessHeap(), 0, emr );




More information about the wine-cvs mailing list