From 3c6197c3d007caa1706c9f5bfeedd4215cbbe43f Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Thu, 12 Jan 2006 18:50:48 +0000 Subject: 2006-01-12 Sebastien Pouliot * GraphicsPath.cs: Throw an ArgumentException if either PathPoints or PathTypes properties are empty (0 length). Note that PathData property still works in that case. * PathData.cs: Don't clone empty arrays (results in NRE). svn path=/trunk/mcs/; revision=55444 --- .../System.Drawing.Drawing2D/ChangeLog | 7 +++++ .../System.Drawing.Drawing2D/GraphicsPath.cs | 20 ++++++++++++-- .../System.Drawing.Drawing2D/PathData.cs | 31 ++++++++++++---------- 3 files changed, 42 insertions(+), 16 deletions(-) (limited to 'mcs/class/System.Drawing') diff --git a/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog b/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog index 97eb9710369..fbdcc38bcd7 100644 --- a/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog +++ b/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog @@ -1,3 +1,10 @@ +2006-01-12 Sebastien Pouliot + + * GraphicsPath.cs: Throw an ArgumentException if either PathPoints or + PathTypes properties are empty (0 length). Note that PathData property + still works in that case. + * PathData.cs: Don't clone empty arrays (results in NRE). + 2005-11-13 Konstantin Triger * GraphicsPath.jvm.cs: AddString support. diff --git a/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.cs b/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.cs index 02bd41d9812..78b23029aa4 100644 --- a/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.cs +++ b/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.cs @@ -146,9 +146,21 @@ namespace System.Drawing.Drawing2D public PathData PathData { get { + int count; + Status status = GDIPlus.GdipGetPointCount (nativePath, out count); + GDIPlus.CheckStatus (status); + + PointF [] points = new PointF [count]; + status = GDIPlus.GdipGetPathPoints (nativePath, points, count); + GDIPlus.CheckStatus (status); + + byte [] types = new byte [count]; + status = GDIPlus.GdipGetPathTypes (nativePath, types, count); + GDIPlus.CheckStatus (status); + PathData pdata = new PathData (); - pdata.Points = PathPoints; - pdata.Types = PathTypes; + pdata.Points = points; + pdata.Types = types; return pdata; } } @@ -158,6 +170,8 @@ namespace System.Drawing.Drawing2D int count; Status status = GDIPlus.GdipGetPointCount (nativePath, out count); GDIPlus.CheckStatus (status); + if (count == 0) + throw new ArgumentException ("PathPoints"); PointF [] points = new PointF [count]; status = GDIPlus.GdipGetPathPoints (nativePath, points, count); @@ -172,6 +186,8 @@ namespace System.Drawing.Drawing2D int count; Status status = GDIPlus.GdipGetPointCount (nativePath, out count); GDIPlus.CheckStatus (status); + if (count == 0) + throw new ArgumentException ("PathTypes"); byte [] types = new byte [count]; status = GDIPlus.GdipGetPathTypes (nativePath, types, count); diff --git a/mcs/class/System.Drawing/System.Drawing.Drawing2D/PathData.cs b/mcs/class/System.Drawing/System.Drawing.Drawing2D/PathData.cs index cbb0d32fef2..f76be5dd3f0 100644 --- a/mcs/class/System.Drawing/System.Drawing.Drawing2D/PathData.cs +++ b/mcs/class/System.Drawing/System.Drawing.Drawing2D/PathData.cs @@ -4,12 +4,10 @@ // Authors: // Dennis Hayes (dennish@Raytek.com) // Andreas Nahr (ClassDevelopment@A-SoftTech.com) +// Sebastien Pouliot // // (C) 2002/3 Ximian, Inc -// - -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -31,27 +29,32 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; - namespace System.Drawing.Drawing2D { - /// - /// Summary description for PathData. - /// public sealed class PathData { - private PointF[] points = null; - private byte[] types = null; + private PointF[] points; + private byte[] types; - public PathData () { } + public PathData () + { + } public PointF[] Points { - get { return (PointF[]) points.Clone (); } + get { + if (points == null) + return null; + return (PointF[]) points.Clone (); + } set { points = value; } } public byte[] Types { - get { return (byte[]) types.Clone (); } + get { + if (types == null) + return null; + return (byte[]) types.Clone (); + } set { types = value; } } -- cgit v1.2.3