Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some coverity before/after null deference checks
  • Loading branch information
nyalldawson committed Jan 27, 2017
1 parent 799b833 commit d259cdf
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
18 changes: 8 additions & 10 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -3917,28 +3917,26 @@ void QgsComposer::cleanupAfterTemplateRead()
{
//test if composer map extent intersects extent of all layers
bool intersects = false;
QgsMapCanvas* canvas = mQgis && mQgis->mapCanvas() ? mQgis->mapCanvas() : nullptr;

QgsRectangle composerMapExtent = mapItem->extent();
if ( mQgis )
if ( canvas )
{
QgsMapCanvas* canvas = mQgis->mapCanvas();
if ( canvas )
QgsRectangle mapCanvasExtent = mQgis->mapCanvas()->fullExtent();
if ( composerMapExtent.intersects( mapCanvasExtent ) )
{
QgsRectangle mapCanvasExtent = mQgis->mapCanvas()->fullExtent();
if ( composerMapExtent.intersects( mapCanvasExtent ) )
{
intersects = true;
}
intersects = true;
}
}

//if not: apply current canvas extent
if ( !intersects )
if ( canvas && !intersects )
{
double currentWidth = mapItem->rect().width();
double currentHeight = mapItem->rect().height();
if ( currentWidth - 0 > 0.0 ) //don't divide through zero
{
QgsRectangle canvasExtent = mQgis->mapCanvas()->mapSettings().visibleExtent();
QgsRectangle canvasExtent = canvas->mapSettings().visibleExtent();
//adapt min y of extent such that the size of the map item stays the same
double newCanvasExtentHeight = currentHeight / currentWidth * canvasExtent.width();
canvasExtent.setYMinimum( canvasExtent.yMaximum() - newCanvasExtentHeight );
Expand Down
3 changes: 2 additions & 1 deletion src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -78,7 +78,8 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend )
mRasterBorderColorButton->setAllowAlpha( true );
mRasterBorderColorButton->setContext( QStringLiteral( "composer " ) );

mMapComboBox->setComposition( legend->composition() );
if ( legend )
mMapComboBox->setComposition( legend->composition() );
mMapComboBox->setItemType( QgsComposerItem::ComposerMap );
connect( mMapComboBox, SIGNAL( itemChanged( QgsComposerItem* ) ), this, SLOT( composerMapChanged( QgsComposerItem* ) ) );

Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -160,8 +160,9 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
if ( eww )
{
eww->setValue( attrs.at( idx ) );
mTableWidget->setCellWidget( i + 1, j, eww->widget() );
mTableWidget->setCellWidget( i + 1, j, eww->widget() );
}
mTableWidget->setCellWidget( i + 1, j, eww->widget() );
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -819,7 +819,8 @@ bool QgsComposerPicture::readXml( const QDomElement& itemElem, const QDomDocumen
mDataDefinedProperties.setProperty( QgsComposerObject::PictureSource, QgsProperty::fromExpression( sourceExpression, expressionActive ) );
}

mSourcePath = mComposition->project()->readPath( itemElem.attribute( QStringLiteral( "file" ) ) );
mSourcePath = mComposition ? mComposition->project()->readPath( itemElem.attribute( QStringLiteral( "file" ) ) )
: itemElem.attribute( QStringLiteral( "file" ) );

//picture rotation
if ( !qgsDoubleNear( itemElem.attribute( QStringLiteral( "pictureRotation" ), QStringLiteral( "0" ) ).toDouble(), 0.0 ) )
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgswmsprojectparser.cpp
Expand Up @@ -1248,7 +1248,7 @@ void QgsWmsProjectParser::addLayers( QDomDocument &doc,
}

QString layerName = currentLayer->name();
if ( mProjectParser && mProjectParser->useLayerIds() )
if ( mProjectParser->useLayerIds() )
layerName = currentLayer->id();
else if ( !currentLayer->shortName().isEmpty() )
layerName = currentLayer->shortName();
Expand Down Expand Up @@ -1626,7 +1626,7 @@ void QgsWmsProjectParser::addOWSLayers( QDomDocument &doc,
layerElem.setAttribute( QStringLiteral( "opacity" ), 1 );

QString lyrname = currentLayer->name();
if ( mProjectParser && mProjectParser->useLayerIds() )
if ( mProjectParser->useLayerIds() )
lyrname = currentLayer->id();
else if ( !currentLayer->shortName().isEmpty() )
lyrname = currentLayer->shortName();
Expand Down
5 changes: 1 addition & 4 deletions src/server/services/wcs/qgswcsgetcapabilities.cpp
Expand Up @@ -106,10 +106,7 @@ namespace QgsWcs
/*
* Adding layer list in contentMetadataElement
*/
if ( configParser )
{
configParser->wcsContentMetadata( contentMetadataElement, doc );
}
configParser->wcsContentMetadata( contentMetadataElement, doc );

return doc;

Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1013,7 +1013,7 @@ namespace QgsWms
{
layerElement = result.createElement( QStringLiteral( "Layer" ) );
QString layerName = currentLayer->name();
if ( mConfigParser && mConfigParser->useLayerIds() )
if ( mConfigParser->useLayerIds() )
layerName = currentLayer->id();
else if ( !currentLayer->shortName().isEmpty() )
layerName = currentLayer->shortName();
Expand Down Expand Up @@ -1792,7 +1792,7 @@ namespace QgsWms
if ( theMapLayer )
{
QString lName = theMapLayer->name();
if ( mConfigParser && mConfigParser->useLayerIds() )
if ( mConfigParser->useLayerIds() )
lName = theMapLayer->id();
else if ( !theMapLayer->shortName().isEmpty() )
lName = theMapLayer->shortName();
Expand Down

0 comments on commit d259cdf

Please sign in to comment.