Skip to content

Commit

Permalink
Fix some potential crashes in curve polygons
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent e6a0af5 commit 6039e05
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/core/geometry/qgscurvepolygon.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgsmulticurve.h" #include "qgsmulticurve.h"
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include <memory>


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


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


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

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


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


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


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


int QgsCurvePolygon::numInteriorRings() const int QgsCurvePolygon::numInteriorRings() const
Expand Down

0 comments on commit 6039e05

Please sign in to comment.