diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2012-02-15 11:25:57 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2012-02-15 11:28:01 +0100 |
commit | d37abad97d72bae0fd0269de12e94c7a7d3fd7e1 (patch) | |
tree | 7463c8759a1a1f09ba1a10bab7a8a7f903609442 /basegfx/source/tools | |
parent | c301199804f5beb7ef803abfa84e04d9351efb3f (diff) |
Fix fdo#45779 - accessing empty polygon.
Guard access to first polygon point.
Diffstat (limited to 'basegfx/source/tools')
-rw-r--r-- | basegfx/source/tools/unotools.cxx | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/basegfx/source/tools/unotools.cxx b/basegfx/source/tools/unotools.cxx index 63b0f4eb02df..6febfd3d527e 100644 --- a/basegfx/source/tools/unotools.cxx +++ b/basegfx/source/tools/unotools.cxx @@ -187,70 +187,73 @@ namespace unotools std::vector<awt::Point> aPoints; aPoints.reserve(nLoopCount); std::vector<drawing::PolygonFlags> aFlags; aFlags.reserve(nLoopCount); - // prepare insert index and current point - basegfx::B2DCubicBezier aBezier; - aBezier.setStartPoint(rPoly.getB2DPoint(0)); - - for(sal_uInt32 b(0L); b<nLoopCount; b++) + if( nCount ) { - // add current point (always) and remember StartPointIndex for evtl. later corrections - const awt::Point aStartPoint(fround(aBezier.getStartPoint().getX()), - fround(aBezier.getStartPoint().getY())); - const sal_uInt32 nStartPointIndex(aPoints.size()); - aPoints.push_back(aStartPoint); - aFlags.push_back(drawing::PolygonFlags_NORMAL); - - // prepare next segment - const sal_uInt32 nNextIndex((b + 1) % nCount); - aBezier.setEndPoint(rPoly.getB2DPoint(nNextIndex)); - aBezier.setControlPointA(rPoly.getNextControlPoint(b)); - aBezier.setControlPointB(rPoly.getPrevControlPoint(nNextIndex)); - - if(aBezier.isBezier()) - { - // if one is used, add always two control points due to the old schema - aPoints.push_back( awt::Point(fround(aBezier.getControlPointA().getX()), - fround(aBezier.getControlPointA().getY())) ); - aFlags.push_back(drawing::PolygonFlags_CONTROL); - - aPoints.push_back( awt::Point(fround(aBezier.getControlPointB().getX()), - fround(aBezier.getControlPointB().getY())) ); - aFlags.push_back(drawing::PolygonFlags_CONTROL); - } + // prepare insert index and current point + basegfx::B2DCubicBezier aBezier; + aBezier.setStartPoint(rPoly.getB2DPoint(0)); - // test continuity with previous control point to set flag value - if(aBezier.getControlPointA() != aBezier.getStartPoint() && (bClosed || b)) + for(sal_uInt32 b(0L); b<nLoopCount; b++) { - const basegfx::B2VectorContinuity eCont(rPoly.getContinuityInPoint(b)); - - if(basegfx::CONTINUITY_C1 == eCont) + // add current point (always) and remember StartPointIndex for evtl. later corrections + const awt::Point aStartPoint(fround(aBezier.getStartPoint().getX()), + fround(aBezier.getStartPoint().getY())); + const sal_uInt32 nStartPointIndex(aPoints.size()); + aPoints.push_back(aStartPoint); + aFlags.push_back(drawing::PolygonFlags_NORMAL); + + // prepare next segment + const sal_uInt32 nNextIndex((b + 1) % nCount); + aBezier.setEndPoint(rPoly.getB2DPoint(nNextIndex)); + aBezier.setControlPointA(rPoly.getNextControlPoint(b)); + aBezier.setControlPointB(rPoly.getPrevControlPoint(nNextIndex)); + + if(aBezier.isBezier()) { - aFlags[nStartPointIndex] = drawing::PolygonFlags_SMOOTH; + // if one is used, add always two control points due to the old schema + aPoints.push_back( awt::Point(fround(aBezier.getControlPointA().getX()), + fround(aBezier.getControlPointA().getY())) ); + aFlags.push_back(drawing::PolygonFlags_CONTROL); + + aPoints.push_back( awt::Point(fround(aBezier.getControlPointB().getX()), + fround(aBezier.getControlPointB().getY())) ); + aFlags.push_back(drawing::PolygonFlags_CONTROL); } - else if(basegfx::CONTINUITY_C2 == eCont) + + // test continuity with previous control point to set flag value + if(aBezier.getControlPointA() != aBezier.getStartPoint() && (bClosed || b)) { - aFlags[nStartPointIndex] = drawing::PolygonFlags_SYMMETRIC; + const basegfx::B2VectorContinuity eCont(rPoly.getContinuityInPoint(b)); + + if(basegfx::CONTINUITY_C1 == eCont) + { + aFlags[nStartPointIndex] = drawing::PolygonFlags_SMOOTH; + } + else if(basegfx::CONTINUITY_C2 == eCont) + { + aFlags[nStartPointIndex] = drawing::PolygonFlags_SYMMETRIC; + } } - } - // prepare next polygon step - aBezier.setStartPoint(aBezier.getEndPoint()); - } + // prepare next polygon step + aBezier.setStartPoint(aBezier.getEndPoint()); + } - if(bClosed) - { - // add first point again as closing point due to old definition - aPoints.push_back( aPoints[0] ); - aFlags.push_back(drawing::PolygonFlags_NORMAL); - } - else - { - // add last point as closing point - const basegfx::B2DPoint aClosingPoint(rPoly.getB2DPoint(nCount - 1L)); - const awt::Point aEnd(fround(aClosingPoint.getX()), - fround(aClosingPoint.getY())); - aPoints.push_back(aEnd); - aFlags.push_back(drawing::PolygonFlags_NORMAL); + if(bClosed) + { + // add first point again as closing point due to old definition + aPoints.push_back( aPoints[0] ); + aFlags.push_back(drawing::PolygonFlags_NORMAL); + } + else + { + // add last point as closing point + const basegfx::B2DPoint aClosingPoint(rPoly.getB2DPoint(nCount - 1L)); + const awt::Point aEnd(fround(aClosingPoint.getX()), + fround(aClosingPoint.getY())); + aPoints.push_back(aEnd); + aFlags.push_back(drawing::PolygonFlags_NORMAL); + } } *pOuterSequence++ = comphelper::containerToSequence(aPoints); |