[10/10] gdiplus: added error checking on draw_polyline
Evan Stade
estade at gmail.com
Tue Jul 10 20:42:06 CDT 2007
Hi,
Changelog:
*changed draw_polyline to return a status
*changed functions that use draw_polyline to read this value
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 939cd76..3d68b70 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
@@ -656,6 +671,7 @@ GpStatus WINGDIPAPI GdipDrawLineI(GpGrap
{
INT save_state;
GpPointF pt[2];
+ GpStatus retval;
if(!pen || !graphics)
return InvalidParameter;
@@ -669,17 +685,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;
@@ -688,11 +705,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