Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some coverity null pointer dereference issues
  • Loading branch information
nyalldawson committed Jan 27, 2017
1 parent 66e10e4 commit bfdd9dc
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 42 deletions.
11 changes: 7 additions & 4 deletions src/app/composer/qgscomposertablebackgroundcolorsdialog.cpp
Expand Up @@ -113,10 +113,13 @@ void QgsComposerTableBackgroundColorsDialog::setGuiElementValues()
Q_FOREACH ( QgsComposerTableV2::CellStyleGroup styleGroup, mCheckBoxMap.keys() )
{
mCheckBoxMap.value( styleGroup )->setChecked( mComposerTable->cellStyle( styleGroup )->enabled );
mColorButtonMap.value( styleGroup )->setEnabled( mComposerTable->cellStyle( styleGroup )->enabled );
mColorButtonMap.value( styleGroup )->setColor( mComposerTable->cellStyle( styleGroup )->cellBackgroundColor );
mColorButtonMap.value( styleGroup )->setAllowAlpha( true );
mColorButtonMap.value( styleGroup )->setColorDialogTitle( tr( "Select background color" ) );
QgsColorButton* button = mColorButtonMap.value( styleGroup );
if ( !button )
continue;
button->setEnabled( mComposerTable->cellStyle( styleGroup )->enabled );
button->setColor( mComposerTable->cellStyle( styleGroup )->cellBackgroundColor );
button->setAllowAlpha( true );
button->setColorDialogTitle( tr( "Select background color" ) );
}

mDefaultColorButton->setColor( mComposerTable->backgroundColor() );
Expand Down
49 changes: 30 additions & 19 deletions src/core/composer/qgscomposertablev2.cpp
Expand Up @@ -231,7 +231,9 @@ bool QgsComposerTableV2::readXml( const QDomElement &itemElem, const QDomDocumen
if ( !styleList.isEmpty() )
{
QDomElement styleElem = styleList.at( 0 ).toElement();
mCellStyles.value( it.key() )->readXml( styleElem );
QgsComposerTableStyle* style = mCellStyles.value( it.key() );
if ( style )
style->readXml( styleElem );
}
}
}
Expand Down Expand Up @@ -1225,24 +1227,33 @@ QString QgsComposerTableV2::wrappedText( const QString &value, double columnWidt
QColor QgsComposerTableV2::backgroundColor( int row, int column ) const
{
QColor color = mBackgroundColor;
if ( mCellStyles.value( OddColumns )->enabled && column % 2 == 0 )
color = mCellStyles.value( OddColumns )->cellBackgroundColor;
if ( mCellStyles.value( EvenColumns )->enabled && column % 2 == 1 )
color = mCellStyles.value( EvenColumns )->cellBackgroundColor;
if ( mCellStyles.value( OddRows )->enabled && row % 2 == 0 )
color = mCellStyles.value( OddRows )->cellBackgroundColor;
if ( mCellStyles.value( EvenRows )->enabled && row % 2 == 1 )
color = mCellStyles.value( EvenRows )->cellBackgroundColor;
if ( mCellStyles.value( FirstColumn )->enabled && column == 0 )
color = mCellStyles.value( FirstColumn )->cellBackgroundColor;
if ( mCellStyles.value( LastColumn )->enabled && column == mColumns.count() - 1 )
color = mCellStyles.value( LastColumn )->cellBackgroundColor;
if ( mCellStyles.value( HeaderRow )->enabled && row == -1 )
color = mCellStyles.value( HeaderRow )->cellBackgroundColor;
if ( mCellStyles.value( FirstRow )->enabled && row == 0 )
color = mCellStyles.value( FirstRow )->cellBackgroundColor;
if ( mCellStyles.value( LastRow )->enabled && row == mTableContents.count() - 1 )
color = mCellStyles.value( LastRow )->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( OddColumns ) )
if ( style->enabled && column % 2 == 0 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( EvenColumns ) )
if ( style->enabled && column % 2 == 1 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( OddRows ) )
if ( style->enabled && row % 2 == 0 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( EvenRows ) )
if ( style->enabled && row % 2 == 1 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( FirstColumn ) )
if ( style->enabled && column == 0 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( LastColumn ) )
if ( style->enabled && column == mColumns.count() - 1 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( HeaderRow ) )
if ( style->enabled && row == -1 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( FirstRow ) )
if ( style->enabled && row == 0 )
color = style->cellBackgroundColor;
if ( QgsComposerTableStyle* style = mCellStyles.value( LastRow ) )
if ( style->enabled && row == mTableContents.count() - 1 )
color = style->cellBackgroundColor;

return color;
}
Expand Down
11 changes: 7 additions & 4 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -520,10 +520,13 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
newElement = relElement;
}

if ( elem.hasAttribute( QStringLiteral( "showLabel" ) ) )
newElement->setShowLabel( elem.attribute( QStringLiteral( "showLabel" ) ).toInt() );
else
newElement->setShowLabel( true );
if ( newElement )
{
if ( elem.hasAttribute( QStringLiteral( "showLabel" ) ) )
newElement->setShowLabel( elem.attribute( QStringLiteral( "showLabel" ) ).toInt() );
else
newElement->setShowLabel( true );
}

return newElement;
}
Expand Down
15 changes: 11 additions & 4 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -746,10 +746,17 @@ void QgsVectorLayerFeatureIterator::addVirtualAttributes( QgsFeature& f )
void QgsVectorLayerFeatureIterator::addExpressionAttribute( QgsFeature& f, int attrIndex )
{
QgsExpression* exp = mExpressionFieldInfo.value( attrIndex );
mExpressionContext->setFeature( f );
QVariant val = exp->evaluate( mExpressionContext.data() );
mSource->mFields.at( attrIndex ).convertCompatible( val );
f.setAttribute( attrIndex, val );
if ( exp )
{
mExpressionContext->setFeature( f );
QVariant val = exp->evaluate( mExpressionContext.data() );
mSource->mFields.at( attrIndex ).convertCompatible( val );
f.setAttribute( attrIndex, val );
}
else
{
f.setAttribute( attrIndex, QVariant() );
}
}

bool QgsVectorLayerFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -948,6 +948,10 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh
myRasterRenderer = myPseudoColorRenderer;
myMinMaxOrigin = myPseudoColorRenderer->minMaxOrigin();
}
else
{
return;
}

Q_FOREACH ( int myBand, myBands )
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/symbology-ng/qgsrendererregistry.cpp
Expand Up @@ -125,7 +125,8 @@ QStringList QgsRendererRegistry::renderersList( QgsRendererAbstractMetadata::Lay
QStringList renderers;
Q_FOREACH ( const QString& renderer, mRenderersOrder )
{
if ( mRenderers.value( renderer )->compatibleLayerTypes() & layerTypes )
QgsRendererAbstractMetadata* r = mRenderers.value( renderer );
if ( r && r->compatibleLayerTypes() & layerTypes )
renderers << renderer;
}
return renderers;
Expand Down
8 changes: 2 additions & 6 deletions src/gui/qgsvariableeditorwidget.cpp
Expand Up @@ -344,12 +344,8 @@ void QgsVariableEditorTree::refreshScopeVariables( QgsExpressionContextScope* sc

Q_FOREACH ( const QString& name, scope->filteredVariableNames() )
{
QTreeWidgetItem* item;
if ( mVariableToItem.contains( qMakePair( scopeIndex, name ) ) )
{
item = mVariableToItem.value( qMakePair( scopeIndex, name ) );
}
else
QTreeWidgetItem* item = mVariableToItem.value( qMakePair( scopeIndex, name ) );
if ( !item )
{
item = new QTreeWidgetItem( scopeItem );
mVariableToItem.insert( qMakePair( scopeIndex, name ), item );
Expand Down
4 changes: 4 additions & 0 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Expand Up @@ -858,6 +858,10 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData * data, Qt::DropAction )
QgsGrassObject vectorObject( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset(), destName, QgsGrassObject::Vector );
import = new QgsGrassVectorImport( vectorProvider, vectorObject ); // takes provider ownership
}
else
{
return false;
}

connect( import, SIGNAL( finished( QgsGrassImport* ) ), SLOT( onImportFinished( QgsGrassImport* ) ) );

Expand Down
7 changes: 4 additions & 3 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -2925,11 +2925,12 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
params.insert( QStringLiteral( "featureType" ), featureTypeName );
params.insert( QStringLiteral( "getFeatureInfoUrl" ), requestUrl.toString() );
featureStore.setParams( params );
Q_FOREACH ( QgsFeatureId id, features.keys() )
QMap<QgsFeatureId, QgsFeature* >::const_iterator featIt = features.constBegin();
for ( ; featIt != features.constEnd(); ++featIt )
{
QgsFeature * feature = features.value( id );
QgsFeature * feature = featIt.value();

QgsDebugMsg( QString( "feature id = %1 : %2 attributes" ).arg( id ).arg( feature->attributes().size() ) );
QgsDebugMsg( QString( "feature id = %1 : %2 attributes" ).arg( featIt.key() ).arg( feature->attributes().size() ) );

if ( coordinateTransform.isValid() && feature->hasGeometry() )
{
Expand Down
5 changes: 4 additions & 1 deletion tests/src/providers/grass/testqgsgrassprovider.cpp
Expand Up @@ -1216,6 +1216,7 @@ void TestQgsGrassProvider::edit()
grassLayer->startEditing();
grassProvider->startEditing( grassLayer );

Q_ASSERT( expectedLayer );
expectedLayer->startEditing();
}

Expand Down Expand Up @@ -1582,7 +1583,9 @@ bool TestQgsGrassProvider::compare( QMap<QString, QgsVectorLayer *> layers, bool
{
Q_FOREACH ( const QString & grassUri, layers.keys() )
{
if ( !compare( grassUri, layers.value( grassUri ), ok ) )
QgsVectorLayer* layer = layers.value( grassUri );
Q_ASSERT( layer );
if ( !compare( grassUri, layer, ok ) )
{
reportRow( "comparison failed: " + grassUri );
}
Expand Down

0 comments on commit bfdd9dc

Please sign in to comment.