From f24a98badcc637ed32ce2f31e623f651c69057e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Mon, 2 Jan 2017 11:53:31 +0000 Subject: [PATCH] ofz#372 check if ImplSplit succeeded Change-Id: I1e34295fe3ee5f77e787f583616d52fa92a0eca4 --- tools/inc/poly.h | 2 +- tools/source/generic/poly.cxx | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/inc/poly.h b/tools/inc/poly.h index d677bcd8b0ac..c614401f122c 100644 --- a/tools/inc/poly.h +++ b/tools/inc/poly.h @@ -42,7 +42,7 @@ public: void ImplSetSize( sal_uInt16 nSize, bool bResize = true ); void ImplCreateFlagArray(); - void ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pInitPoly = NULL ); + bool ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pInitPoly = NULL ); }; #define MAX_POLYGONS ((sal_uInt16)0x3FF0) diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index 457a05b4d112..2c89775e79d0 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -208,13 +208,16 @@ void ImplPolygon::ImplSetSize( sal_uInt16 nNewSize, bool bResize ) mnPoints = nNewSize; } -void ImplPolygon::ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pInitPoly ) +bool ImplPolygon::ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pInitPoly ) { const sal_uIntPtr nSpaceSize = nSpace * sizeof( Point ); //Can't fit this in :-(, throw ? if (mnPoints + nSpace > USHRT_MAX) - return; + { + SAL_WARN("tools", "Polygon needs " << mnPoints + nSpace << " points, but only " << USHRT_MAX << " possible"); + return false; + } const sal_uInt16 nNewSize = mnPoints + nSpace; @@ -269,6 +272,8 @@ void ImplPolygon::ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pI mpPointAry = pNewAry; mnPoints = nNewSize; } + + return true; } void ImplPolygon::ImplCreateFlagArray() @@ -1444,13 +1449,15 @@ void Polygon::Insert( sal_uInt16 nPos, const Point& rPt, PolyFlags eFlags ) if( nPos >= mpImplPolygon->mnPoints ) nPos = mpImplPolygon->mnPoints; - mpImplPolygon->ImplSplit( nPos, 1 ); - mpImplPolygon->mpPointAry[ nPos ] = rPt; - - if( POLY_NORMAL != eFlags ) + if (mpImplPolygon->ImplSplit(nPos, 1)) { - mpImplPolygon->ImplCreateFlagArray(); - mpImplPolygon->mpFlagAry[ nPos ] = (sal_uInt8) eFlags; + mpImplPolygon->mpPointAry[ nPos ] = rPt; + + if( POLY_NORMAL != eFlags ) + { + mpImplPolygon->ImplCreateFlagArray(); + mpImplPolygon->mpFlagAry[ nPos ] = (sal_uInt8) eFlags; + } } } -- 2.12.2