[9/18] gdiplus: added draw_polyline error checking

Evan Stade estade at gmail.com
Wed Jul 11 20:07:44 CDT 2007


Hi,

Changelog:
*changed draw_polyline to return a status
*changed the functions that use this helper to use the status

 dlls/gdiplus/graphics.c |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

-- 
Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 2a3ea33..93cbcd1 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -282,12 +282,23 @@ static void shorten_line_amt(REAL x1, RE
 
 /* Draws lines between the given points, and if caps is true then draws an endcap
  * at the end of the last line.  FIXME: Startcaps not implemented. */
-static void draw_polyline(HDC hdc, GpPen *pen, GDIPCONST GpPointF * pt,
+static GpStatus draw_polyline(HDC hdc, GpPen *pen, GDIPCONST GpPointF * pt,
     INT count, BOOL caps)
 {
-    POINT *pti = GdipAlloc(count * sizeof(POINT));
+    POINT *pti;
     REAL x = pt[count - 1].X, y = pt[count - 1].Y;
     INT i;
+    GpStatus status = GenericError;
+
+    if(!count)
+        return Ok;
+
+    pti = GdipAlloc(count * sizeof(POINT));
+
+    if(!pti){
+        status = OutOfMemory;
+        goto end;
+    }
 
     if(caps){
         if(pen->endcap == LineCapArrowAnchor)
@@ -306,7 +317,11 @@ static void draw_polyline(HDC hdc, GpPen
     pti[i].y = roundr(y);
 
     Polyline(hdc, pti, count);
+
+end:
     GdipFree(pti);
+
+    return status;
 }
 
 /* Conducts a linear search to find the bezier points that will back off
@@ -660,6 +675,7 @@ GpStatus WINGDIPAPI GdipDrawLineI(GpGrap
 {
     INT save_state;
     GpPointF pt[2];
+    GpStatus retval;
 
     if(!pen || !graphics)
         return InvalidParameter;
@@ -673,17 +689,18 @@ GpStatus WINGDIPAPI GdipDrawLineI(GpGrap
     EndPath(graphics->hdc);
     SelectObject(graphics->hdc, pen->gdipen);
 
-    draw_polyline(graphics->hdc, pen, pt, 2, TRUE);
+    retval = draw_polyline(graphics->hdc, pen, pt, 2, TRUE);
 
     RestoreDC(graphics->hdc, save_state);
 
-    return Ok;
+    return retval;
 }
 
 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
     GpPointF *points, INT count)
 {
     INT save_state;
+    GpStatus retval;
 
     if(!pen || !graphics || (count < 2))
         return InvalidParameter;
@@ -692,11 +709,11 @@ GpStatus WINGDIPAPI GdipDrawLines(GpGrap
     EndPath(graphics->hdc);
     SelectObject(graphics->hdc, pen->gdipen);
 
-    draw_polyline(graphics->hdc, pen, points, count, TRUE);
+    retval = draw_polyline(graphics->hdc, pen, points, count, TRUE);
 
     RestoreDC(graphics->hdc, save_state);
 
-    return Ok;
+    return retval;
 }
 
 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
-- 
1.4.1


More information about the wine-patches mailing list