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