Skip to content

Commit 62a97e6

Browse files
author
Caolán McNamara
committed
ofz#372 check if ImplSplit succeeded
Change-Id: I1e34295fe3ee5f77e787f583616d52fa92a0eca4
1 parent 2cdaab4 commit 62a97e6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Diff for: tools/inc/poly.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SAL_WARN_UNUSED ImplPolygon : public ImplPolygonData
4343

4444
void ImplSetSize( sal_uInt16 nSize, bool bResize = true );
4545
void ImplCreateFlagArray();
46-
void ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon const * pInitPoly = nullptr );
46+
bool ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon const * pInitPoly = nullptr );
4747
};
4848

4949
#define MAX_POLYGONS ((sal_uInt16)0x3FF0)

Diff for: tools/source/generic/poly.cxx

+9-4
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,14 @@ void ImplPolygon::ImplSetSize( sal_uInt16 nNewSize, bool bResize )
212212
mnPoints = nNewSize;
213213
}
214214

215-
void ImplPolygon::ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon const * pInitPoly )
215+
bool ImplPolygon::ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon const * pInitPoly )
216216
{
217217
//Can't fit this in :-(, throw ?
218218
if (mnPoints + nSpace > USHRT_MAX)
219-
return;
219+
{
220+
SAL_WARN("tools", "Polygon needs " << mnPoints + nSpace << " points, but only " << USHRT_MAX << " possible");
221+
return false;
222+
}
220223

221224
const sal_uInt16 nNewSize = mnPoints + nSpace;
222225
const std::size_t nSpaceSize = static_cast<std::size_t>(nSpace) * sizeof(Point);
@@ -272,6 +275,8 @@ void ImplPolygon::ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon con
272275
mpPointAry = pNewAry;
273276
mnPoints = nNewSize;
274277
}
278+
279+
return true;
275280
}
276281

277282
void ImplPolygon::ImplCreateFlagArray()
@@ -1472,8 +1477,8 @@ void Polygon::Insert( sal_uInt16 nPos, const Point& rPt )
14721477
if( nPos >= mpImplPolygon->mnPoints )
14731478
nPos = mpImplPolygon->mnPoints;
14741479

1475-
mpImplPolygon->ImplSplit( nPos, 1 );
1476-
mpImplPolygon->mpPointAry[ nPos ] = rPt;
1480+
if (mpImplPolygon->ImplSplit(nPos, 1))
1481+
mpImplPolygon->mpPointAry[ nPos ] = rPt;
14771482
}
14781483

14791484
void Polygon::Insert( sal_uInt16 nPos, const tools::Polygon& rPoly )

0 commit comments

Comments
 (0)