Merge pull request #5552 from elpaso/vector_layer_safe_cast

[bugfix] Prevent a bad crash when provider is wrong
This commit is contained in:
Alessandro Pasotti 2017-11-07 11:56:24 +01:00 committed by GitHub
commit a22e565dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1530,12 +1530,8 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
dataSource = uri.uri( false );
}
// XXX when execution gets here.
//XXX - This was a dynamic cast but that kills the Windows
// version big-time with an abnormal termination error
delete mDataProvider;
mDataProvider = ( QgsVectorDataProvider * )( QgsProviderRegistry::instance()->createProvider( provider, dataSource ) );
mDataProvider = qobject_cast<QgsVectorDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource ) );
if ( !mDataProvider )
{
QgsDebugMsg( " unable to get data provider" );