From: David Kahurani k.kahurani@gmail.com
Serves to strictly allocate the requested size to a path unlike lengthen_path whose algorithm allocates more than strictly required
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/gdiplus/gdiplus.c | 18 ++++++++++++++++++ dlls/gdiplus/gdiplus_private.h | 1 + dlls/gdiplus/graphicspath.c | 19 ++----------------- dlls/gdiplus/metafile.c | 11 ++--------- 4 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c index 32e287b0409..020a9de8acc 100644 --- a/dlls/gdiplus/gdiplus.c +++ b/dlls/gdiplus/gdiplus.c @@ -442,6 +442,24 @@ BOOL lengthen_path(GpPath *path, INT len) return TRUE; }
+BOOL lengthen_path_strict(GpPath *path, INT len) +{ + /* Strictly allocate the requested memory size */ + /* Used only on fresh paths */ + path->pathdata.Points = calloc(len, sizeof(PointF)); + path->pathdata.Types = calloc(1, len); + + if (!path->pathdata.Points || !path->pathdata.Types) + { + free(path->pathdata.Points); + free(path->pathdata.Types); + free(path); + return FALSE; + } + + return TRUE; +} + void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height, BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) { diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 6f7e72124c2..0dae222ed12 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -130,6 +130,7 @@ extern void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj, extern void free_installed_fonts(void);
extern BOOL lengthen_path(GpPath *path, INT len); +extern BOOL lengthen_path_strict(GpPath *path, INT len);
extern DWORD write_region_data(const GpRegion *region, void *data); extern DWORD write_path_data(GpPath *path, void *data); diff --git a/dlls/gdiplus/graphicspath.c b/dlls/gdiplus/graphicspath.c index 24c2888cfe8..7b85355773a 100644 --- a/dlls/gdiplus/graphicspath.c +++ b/dlls/gdiplus/graphicspath.c @@ -1184,14 +1184,7 @@ GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
**clone = *path;
- (*clone)->pathdata.Points = malloc(path->datalen * sizeof(PointF)); - (*clone)->pathdata.Types = malloc(path->datalen); - if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){ - free((*clone)->pathdata.Points); - free((*clone)->pathdata.Types); - free(*clone); - return OutOfMemory; - } + if (!lengthen_path_strict(*clone, path->datalen)) return OutOfMemory;
memcpy((*clone)->pathdata.Points, path->pathdata.Points, path->datalen * sizeof(PointF)); @@ -1284,15 +1277,7 @@ GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points, } }
- (*path)->pathdata.Points = malloc(count * sizeof(PointF)); - (*path)->pathdata.Types = malloc(count); - - if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){ - free((*path)->pathdata.Points); - free((*path)->pathdata.Types); - free(*path); - return OutOfMemory; - } + if (!lengthen_path_strict(*path, count)) return OutOfMemory;
memcpy((*path)->pathdata.Points, points, count * sizeof(PointF)); memcpy((*path)->pathdata.Types, types, count); diff --git a/dlls/gdiplus/metafile.c b/dlls/gdiplus/metafile.c index 5c50d0d1d37..30e69ee4668 100644 --- a/dlls/gdiplus/metafile.c +++ b/dlls/gdiplus/metafile.c @@ -2039,16 +2039,9 @@ static GpStatus metafile_deserialize_path(const BYTE *record_data, UINT data_siz if (status != Ok) return status;
- (*path)->pathdata.Count = data->PathPointCount; - (*path)->pathdata.Points = malloc(data->PathPointCount * sizeof(*(*path)->pathdata.Points)); - (*path)->pathdata.Types = malloc(data->PathPointCount * sizeof(*(*path)->pathdata.Types)); - (*path)->datalen = (*path)->pathdata.Count; + if (!lengthen_path_strict(*path, data->PathPointCount)) return OutOfMemory;
- if (!(*path)->pathdata.Points || !(*path)->pathdata.Types) - { - GdipDeletePath(*path); - return OutOfMemory; - } + (*path)->datalen = (*path)->pathdata.Count;
if (data->PathPointFlags & 0x4000) /* C */ {