Avoid a segfault when NULL layer is passed to vector writer

This commit is contained in:
Martin Dobias 2011-08-04 19:48:54 +02:00
parent aa121bf67a
commit 2d35b16aae
3 changed files with 12 additions and 1 deletions

View File

@ -21,7 +21,12 @@ public:
NoError = 0, NoError = 0,
ErrDriverNotFound, ErrDriverNotFound,
ErrCreateDataSource, ErrCreateDataSource,
ErrCreateLayer ErrCreateLayer,
ErrAttributeTypeUnsupported,
ErrAttributeCreationFailed,
ErrProjection, // added in 1.5
ErrFeatureWriteFailed, // added in 1.6
ErrInvalidLayer, // added in 2.0
}; };
/** Write contents of vector layer to a shapefile /** Write contents of vector layer to a shapefile

View File

@ -588,6 +588,11 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
QgsCoordinateTransform* ct = 0; QgsCoordinateTransform* ct = 0;
int shallTransform = false; int shallTransform = false;
if ( layer == NULL )
{
return ErrInvalidLayer;
}
if ( destCRS && destCRS->isValid() ) if ( destCRS && destCRS->isValid() )
{ {
// This means we should transform // This means we should transform

View File

@ -53,6 +53,7 @@ class CORE_EXPORT QgsVectorFileWriter
ErrAttributeCreationFailed, ErrAttributeCreationFailed,
ErrProjection, // added in 1.5 ErrProjection, // added in 1.5
ErrFeatureWriteFailed, // added in 1.6 ErrFeatureWriteFailed, // added in 1.6
ErrInvalidLayer, // added in 2.0
}; };
/** Write contents of vector layer to a shapefile /** Write contents of vector layer to a shapefile