Skip to content
Permalink
Browse files

Coverity null dereference fixes

  • Loading branch information
nyalldawson committed Feb 11, 2015
1 parent a15aa74 commit 868720b7e0c53f9d8cb94a3630c50180d25b4e5f
@@ -553,11 +553,14 @@ void QgsComposerAttributeTableWidget::atlasToggled()
bool atlasEnabled = atlasComposition() && atlasComposition()->enabled();
toggleAtlasSpecificControls( atlasEnabled );

if ( !mComposerTable )
return;

mSourceComboBox->blockSignals( true );
mSourceComboBox->setCurrentIndex( mSourceComboBox->findData( mComposerTable->source() ) );
mSourceComboBox->blockSignals( false );

if ( !atlasEnabled && mComposerTable && mComposerTable->filterToAtlasFeature() )
if ( !atlasEnabled && mComposerTable->filterToAtlasFeature() )
{
mComposerTable->setFilterToAtlasFeature( false );
}
@@ -2516,6 +2516,10 @@ void QgisApp::autoSelectAddedLayer( QList<QgsMapLayer*> layers )
if ( layers.count() )
{
QgsLayerTreeLayer* nodeLayer = QgsProject::instance()->layerTreeRoot()->findLayer( layers[0]->id() );

if ( !nodeLayer )
return;

QModelIndex index = mLayerTreeView->layerTreeModel()->node2index( nodeLayer );
mLayerTreeView->setCurrentIndex( index );
}
@@ -7456,7 +7460,10 @@ void QgisApp::loadPythonSupport()

//QgsDebugMsg("Python support library's instance() symbol resolved.");
mPythonUtils = pythonlib_inst();
mPythonUtils->initPython( mQgisInterface );
if ( mPythonUtils )
{
mPythonUtils->initPython( mQgisInterface );
}

if ( mPythonUtils && mPythonUtils->isEnabled() )
{
@@ -9205,12 +9212,6 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
bool layerHasSelection = vlayer->selectedFeatureCount() > 0;
bool layerHasActions = vlayer->actions()->size() + QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).size() > 0;

bool canChangeAttributes = dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures;
bool canSupportEditing = dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities;
bool canChangeGeometry = dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;

mActionLocalHistogramStretch->setEnabled( false );
mActionFullHistogramStretch->setEnabled( false );
mActionLocalCumulativeCutStretch->setEnabled( false );
@@ -9242,6 +9243,12 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

if ( dprovider )
{
bool canChangeAttributes = dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures;
bool canSupportEditing = dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities;
bool canChangeGeometry = dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;

mActionLayerSubsetString->setEnabled( !isEditable && dprovider->supportsSubsetString() );

mActionToggleEditing->setEnabled( canSupportEditing && !vlayer->isReadOnly() );
@@ -137,6 +137,9 @@ void QgsFieldCalculator::accept()
{
builder->saveToRecent( "fieldcalc" );

if ( !mVectorLayer )
return;

// Set up QgsDistanceArea each time we (re-)calculate
QgsDistanceArea myDa;

@@ -149,9 +152,6 @@ void QgsFieldCalculator::accept()
QgsExpression exp( calcString );
exp.setGeomCalculator( myDa );

if ( !mVectorLayer )
return;

if ( ! exp.prepare( mVectorLayer->pendingFields() ) )
{
QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() );
@@ -173,7 +173,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();

// Only do pyramids if dealing directly with GDAL.
if ( provider->capabilities() & QgsRasterDataProvider::BuildPyramids )
if ( provider && provider->capabilities() & QgsRasterDataProvider::BuildPyramids )
{
// initialize resampling methods
cboResamplingMethod->clear();
@@ -213,7 +213,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
// We can calculate histogram for all data sources but estimated only if
// size is unknown - could also be enabled if well supported (estimated histogram
// and and let user know that it is estimated)
if ( !( provider->capabilities() & QgsRasterDataProvider::Size ) )
if ( !provider || !( provider->capabilities() & QgsRasterDataProvider::Size ) )
{
// disable Histogram tab completely
mOptsPage_Histogram->setEnabled( false );
@@ -111,6 +111,9 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
connect( htmlRadio, SIGNAL( toggled( bool ) ), insertExpressionButton, SLOT( setEnabled( bool ) ) );
connect( fieldComboRadio, SIGNAL( toggled( bool ) ), displayFieldComboBox, SLOT( setEnabled( bool ) ) );

if ( !layer )
return;

QVBoxLayout *layout;

if ( layer->hasGeometryType() )
@@ -236,38 +239,35 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mDiagramFrame->layout()->addWidget( diagramPropertiesDialog );

//layer title and abstract
if ( layer )
{
mLayerTitleLineEdit->setText( layer->title() );
mLayerAbstractTextEdit->setPlainText( layer->abstract() );
mLayerKeywordListLineEdit->setText( layer->keywordList() );
mLayerDataUrlLineEdit->setText( layer->dataUrl() );
mLayerDataUrlFormatComboBox->setCurrentIndex(
mLayerDataUrlFormatComboBox->findText(
layer->dataUrlFormat()
)
);
//layer attribution and metadataUrl
mLayerAttributionLineEdit->setText( layer->attribution() );
mLayerAttributionUrlLineEdit->setText( layer->attributionUrl() );
mLayerMetadataUrlLineEdit->setText( layer->metadataUrl() );
mLayerMetadataUrlTypeComboBox->setCurrentIndex(
mLayerMetadataUrlTypeComboBox->findText(
layer->metadataUrlType()
)
);
mLayerMetadataUrlFormatComboBox->setCurrentIndex(
mLayerMetadataUrlFormatComboBox->findText(
layer->metadataUrlFormat()
)
);
mLayerLegendUrlLineEdit->setText( layer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex(
mLayerLegendUrlFormatComboBox->findText(
layer->legendUrlFormat()
)
);
}
mLayerTitleLineEdit->setText( layer->title() );
mLayerAbstractTextEdit->setPlainText( layer->abstract() );
mLayerKeywordListLineEdit->setText( layer->keywordList() );
mLayerDataUrlLineEdit->setText( layer->dataUrl() );
mLayerDataUrlFormatComboBox->setCurrentIndex(
mLayerDataUrlFormatComboBox->findText(
layer->dataUrlFormat()
)
);
//layer attribution and metadataUrl
mLayerAttributionLineEdit->setText( layer->attribution() );
mLayerAttributionUrlLineEdit->setText( layer->attributionUrl() );
mLayerMetadataUrlLineEdit->setText( layer->metadataUrl() );
mLayerMetadataUrlTypeComboBox->setCurrentIndex(
mLayerMetadataUrlTypeComboBox->findText(
layer->metadataUrlType()
)
);
mLayerMetadataUrlFormatComboBox->setCurrentIndex(
mLayerMetadataUrlFormatComboBox->findText(
layer->metadataUrlFormat()
)
);
mLayerLegendUrlLineEdit->setText( layer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex(
mLayerLegendUrlFormatComboBox->findText(
layer->legendUrlFormat()
)
);

QSettings settings;
// if dialog hasn't been opened/closed yet, default to Styles tab, which is used most often
@@ -52,10 +52,13 @@ bool QgsDatumTransformStore::hasEntryForLayer( QgsMapLayer* layer ) const

const QgsCoordinateTransform* QgsDatumTransformStore::transformation( QgsMapLayer* layer ) const
{
if ( !layer )
return 0;

QString srcAuthId = layer->crs().authid();
QString dstAuthId = mDestCRS.authid();

if ( !layer || srcAuthId == dstAuthId )
if ( srcAuthId == dstAuthId )
{
return 0;
}
@@ -572,17 +572,20 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
QgsLayerTreeGroup* layerTreeRoot = QgsProject::instance()->layerTreeRoot();
// Find the parent group of the original layer
QgsLayerTreeLayer* layerTreeLayer = layerTreeRoot->findLayer( layer->id() );
QgsLayerTreeGroup* parentTreeGroup = qobject_cast<QgsLayerTreeGroup*>( layerTreeLayer->parent() );
if ( parentTreeGroup )
if ( layerTreeLayer )
{
int index = parentTreeGroup->children().indexOf( layerTreeLayer );
// Move the new layer from the root group to the new group
QgsLayerTreeLayer* newLayerTreeLayer = layerTreeRoot->findLayer( newLayer->id() );
QgsLayerTreeNode* newLayerTreeLayerClone = newLayerTreeLayer->clone();
QgsLayerTreeGroup* grp = qobject_cast<QgsLayerTreeGroup*>( newLayerTreeLayer->parent() );
parentTreeGroup->insertChildNode( index, newLayerTreeLayerClone );
if ( grp )
grp->removeChildNode( newLayerTreeLayer );
QgsLayerTreeGroup* parentTreeGroup = qobject_cast<QgsLayerTreeGroup*>( layerTreeLayer->parent() );
if ( parentTreeGroup )
{
int index = parentTreeGroup->children().indexOf( layerTreeLayer );
// Move the new layer from the root group to the new group
QgsLayerTreeLayer* newLayerTreeLayer = layerTreeRoot->findLayer( newLayer->id() );
QgsLayerTreeNode* newLayerTreeLayerClone = newLayerTreeLayer->clone();
QgsLayerTreeGroup* grp = qobject_cast<QgsLayerTreeGroup*>( newLayerTreeLayer->parent() );
parentTreeGroup->insertChildNode( index, newLayerTreeLayerClone );
if ( grp )
grp->removeChildNode( newLayerTreeLayer );
}
}

if ( hasLabels )
@@ -112,11 +112,11 @@ void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const
// which should not harm anything
p->setBrush( QBrush( QColor( Qt::white ), Qt::NoBrush ) );

int w = theQgsMapToPixel->mapWidth();
int h = theQgsMapToPixel->mapHeight();

if ( theQgsMapToPixel )
{
int w = theQgsMapToPixel->mapWidth();
int h = theQgsMapToPixel->mapHeight();

double rotation = theQgsMapToPixel->mapRotation();
if ( rotation )
{
@@ -464,9 +464,11 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste
}

const QgsRasterInterface* iface = iter->input();
if ( !iface )
return SourceProviderError;

QGis::DataType inputDataType = iface->dataType( 1 );
if ( !iface || ( inputDataType != QGis::ARGB32 &&
inputDataType != QGis::ARGB32_Premultiplied ) )
if ( inputDataType != QGis::ARGB32 && inputDataType != QGis::ARGB32_Premultiplied )
{
return SourceProviderError;
}
@@ -97,9 +97,10 @@ bool QgsRasterPipe::insert( int idx, QgsRasterInterface* theInterface )

bool QgsRasterPipe::replace( int idx, QgsRasterInterface* theInterface )
{
if ( !theInterface ) return false;

QgsDebugMsg( QString( "replace by %1 at %2" ).arg( typeid( *theInterface ).name() ).arg( idx ) );
if ( !checkBounds( idx ) ) return false;
if ( !theInterface ) return false;

// make a copy of pipe to test connection, we test the connections
// of the whole pipe, because the types and band numbers may change
@@ -152,10 +153,9 @@ void QgsRasterPipe::unsetRole( QgsRasterInterface * theInterface )

bool QgsRasterPipe::set( QgsRasterInterface* theInterface )
{
QgsDebugMsg( QString( "%1" ).arg( typeid( *theInterface ).name() ) );

if ( !theInterface ) return false;

QgsDebugMsg( QString( "%1" ).arg( typeid( *theInterface ).name() ) );
Role role = interfaceRole( theInterface );

// We don't know where to place unknown interface
@@ -204,7 +204,7 @@ QgsRasterRenderer* QgsRasterRendererRegistry::defaultRendererForDrawingStyle( co
break;
}
default:
break;
return 0;
}

QgsRasterTransparency* tr = new QgsRasterTransparency(); //renderer takes ownership
@@ -197,7 +197,8 @@ void QgsLayerTreeView::onCurrentChanged()
if ( layerCurrent )
{
QgsLayerTreeLayer* nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerCurrentID );
nodeLayerIndex = layerTreeModel()->node2index( nodeLayer );
if ( nodeLayer )
nodeLayerIndex = layerTreeModel()->node2index( nodeLayer );
}
layerTreeModel()->setCurrentIndex( nodeLayerIndex );

@@ -93,19 +93,19 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )

//set combo entries to current values
blockComboSignals( true );
mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
QPointF offsetPt = mLayer->offset();
spinOffsetX->setValue( offsetPt.x() );
spinOffsetY->setValue( offsetPt.y() );
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
QPointF offsetPt = mLayer->offset();
spinOffsetX->setValue( offsetPt.x() );
spinOffsetY->setValue( offsetPt.y() );
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
blockComboSignals( false );

registerDataDefinedButton( mSymbolWidthDDBtn, "width", QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
@@ -124,7 +124,7 @@ QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVecto
blockAllSignals( false );

//set the appropriate renderer dialog
if ( mRenderer && mRenderer->embeddedRenderer() )
if ( mRenderer->embeddedRenderer() )
{
QString rendererName = mRenderer->embeddedRenderer()->type();
int rendererIndex = mRendererComboBox->findData( rendererName );
@@ -111,6 +111,10 @@ void QgsGCPListModel::updateModel()
{
int j = 0;
QgsGeorefDataPoint *p = mGCPList->at( i );

if ( !p )
continue;

p->setId( i );

QStandardItem *si = new QStandardItem();
@@ -159,10 +163,7 @@ void QgsGCPListModel::updateModel()
}
residual = sqrt( dX * dX + dY * dY );

if ( p )
{
p->setResidual( QPointF( dX, dY ) );
}
p->setResidual( QPointF( dX, dY ) );

if ( residual >= 0.f )
{
@@ -159,8 +159,8 @@ void QgsSpatialQueryDialog::evaluateCheckBoxLayer( bool isTarget )
lyr = mLayerReference;
checkbox = ckbUsingSelectedReference;
}
int selectedCount = lyr->selectedFeatureCount();
bool isCheckBoxValid = ( lyr != NULL && selectedCount > 0 );
int selectedCount = lyr ? lyr->selectedFeatureCount() : 0;
bool isCheckBoxValid = selectedCount > 0;
checkbox->setChecked( isCheckBoxValid );
checkbox->setEnabled( isCheckBoxValid );
QString textCheckBox = isCheckBoxValid
@@ -143,6 +143,7 @@ bool topolTest::testCancelled()
return false;
}

#if 0 //unused and totally broken - index is set to null and then immediately dereferenced
ErrorList topolTest::checkCloseFeature( double tolerance, QgsVectorLayer* layer1, QgsVectorLayer* layer2, bool isExtent )
{
Q_UNUSED( isExtent );
@@ -223,6 +224,7 @@ ErrorList topolTest::checkCloseFeature( double tolerance, QgsVectorLayer* layer1

return errorList;
}
#endif

ErrorList topolTest::checkDanglingLines( double tolerance, QgsVectorLayer* layer1, QgsVectorLayer* layer2, bool isExtent )
{

0 comments on commit 868720b

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