Skip to content
Permalink
Browse files

Fix some potential crashes in curve polygons

  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent e6a0af5 commit 6039e05b49cfc919de8debcd0e1b760a4d83c107
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/core/geometry/qgscurvepolygon.cpp
@@ -26,6 +26,7 @@
#include "qgsmulticurve.h"
#include <QPainter>
#include <QPainterPath>
#include <memory>

QgsCurvePolygon::QgsCurvePolygon(): QgsSurface()
{
@@ -452,7 +453,10 @@ double QgsCurvePolygon::perimeter() const

QgsPolygonV2 *QgsCurvePolygon::surfaceToPolygon() const
{
QgsPolygonV2 *polygon = new QgsPolygonV2();
std::unique_ptr< QgsPolygonV2 > polygon( new QgsPolygonV2() );
if ( !mExteriorRing )
return polygon.release();

polygon->setExteriorRing( exteriorRing()->curveToLine() );
QList<QgsCurve *> interiors;
int n = numInteriorRings();
@@ -462,11 +466,14 @@ QgsPolygonV2 *QgsCurvePolygon::surfaceToPolygon() const
interiors.append( interiorRing( i )->curveToLine() );
}
polygon->setInteriorRings( interiors );
return polygon;
return polygon.release();
}

QgsAbstractGeometry *QgsCurvePolygon::boundary() const
{
if ( !mExteriorRing )
return nullptr;

if ( mInteriorRings.isEmpty() )
{
return mExteriorRing->clone();
@@ -486,12 +493,12 @@ QgsAbstractGeometry *QgsCurvePolygon::boundary() const

QgsPolygonV2 *QgsCurvePolygon::toPolygon( double tolerance, SegmentationToleranceType toleranceType ) const
{
std::unique_ptr< QgsPolygonV2 > poly( new QgsPolygonV2() );
if ( !mExteriorRing )
{
return nullptr;
return poly.release();
}

QgsPolygonV2 *poly = new QgsPolygonV2();
poly->setExteriorRing( mExteriorRing->curveToLine( tolerance, toleranceType ) );

QList<QgsCurve *> rings;
@@ -501,7 +508,7 @@ QgsPolygonV2 *QgsCurvePolygon::toPolygon( double tolerance, SegmentationToleranc
rings.push_back( ( *it )->curveToLine( tolerance, toleranceType ) );
}
poly->setInteriorRings( rings );
return poly;
return poly.release();
}

int QgsCurvePolygon::numInteriorRings() const

0 comments on commit 6039e05

Please sign in to comment.
You can’t perform that action at this time.