Fix some coverity null pointer dereference issues

This commit is contained in:
Nyall Dawson 2017-01-27 16:52:13 +10:00
parent 66e10e4937
commit bfdd9dc0b0
10 changed files with 75 additions and 42 deletions

View File

@ -113,10 +113,13 @@ void QgsComposerTableBackgroundColorsDialog::setGuiElementValues()
Q_FOREACH ( QgsComposerTableV2::CellStyleGroup styleGroup, mCheckBoxMap.keys() ) Q_FOREACH ( QgsComposerTableV2::CellStyleGroup styleGroup, mCheckBoxMap.keys() )
{ {
mCheckBoxMap.value( styleGroup )->setChecked( mComposerTable->cellStyle( styleGroup )->enabled ); mCheckBoxMap.value( styleGroup )->setChecked( mComposerTable->cellStyle( styleGroup )->enabled );
mColorButtonMap.value( styleGroup )->setEnabled( mComposerTable->cellStyle( styleGroup )->enabled ); QgsColorButton* button = mColorButtonMap.value( styleGroup );
mColorButtonMap.value( styleGroup )->setColor( mComposerTable->cellStyle( styleGroup )->cellBackgroundColor ); if ( !button )
mColorButtonMap.value( styleGroup )->setAllowAlpha( true ); continue;
mColorButtonMap.value( styleGroup )->setColorDialogTitle( tr( "Select background color" ) ); 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() ); mDefaultColorButton->setColor( mComposerTable->backgroundColor() );

View File

@ -231,7 +231,9 @@ bool QgsComposerTableV2::readXml( const QDomElement &itemElem, const QDomDocumen
if ( !styleList.isEmpty() ) if ( !styleList.isEmpty() )
{ {
QDomElement styleElem = styleList.at( 0 ).toElement(); QDomElement styleElem = styleList.at( 0 ).toElement();
mCellStyles.value( it.key() )->readXml( styleElem ); QgsComposerTableStyle* style = mCellStyles.value( it.key() );
if ( style )
style->readXml( styleElem );
} }
} }
} }
@ -1225,24 +1227,33 @@ QString QgsComposerTableV2::wrappedText( const QString &value, double columnWidt
QColor QgsComposerTableV2::backgroundColor( int row, int column ) const QColor QgsComposerTableV2::backgroundColor( int row, int column ) const
{ {
QColor color = mBackgroundColor; QColor color = mBackgroundColor;
if ( mCellStyles.value( OddColumns )->enabled && column % 2 == 0 ) if ( QgsComposerTableStyle* style = mCellStyles.value( OddColumns ) )
color = mCellStyles.value( OddColumns )->cellBackgroundColor; if ( style->enabled && column % 2 == 0 )
if ( mCellStyles.value( EvenColumns )->enabled && column % 2 == 1 ) color = style->cellBackgroundColor;
color = mCellStyles.value( EvenColumns )->cellBackgroundColor; if ( QgsComposerTableStyle* style = mCellStyles.value( EvenColumns ) )
if ( mCellStyles.value( OddRows )->enabled && row % 2 == 0 ) if ( style->enabled && column % 2 == 1 )
color = mCellStyles.value( OddRows )->cellBackgroundColor; color = style->cellBackgroundColor;
if ( mCellStyles.value( EvenRows )->enabled && row % 2 == 1 ) if ( QgsComposerTableStyle* style = mCellStyles.value( OddRows ) )
color = mCellStyles.value( EvenRows )->cellBackgroundColor; if ( style->enabled && row % 2 == 0 )
if ( mCellStyles.value( FirstColumn )->enabled && column == 0 ) color = style->cellBackgroundColor;
color = mCellStyles.value( FirstColumn )->cellBackgroundColor; if ( QgsComposerTableStyle* style = mCellStyles.value( EvenRows ) )
if ( mCellStyles.value( LastColumn )->enabled && column == mColumns.count() - 1 ) if ( style->enabled && row % 2 == 1 )
color = mCellStyles.value( LastColumn )->cellBackgroundColor; color = style->cellBackgroundColor;
if ( mCellStyles.value( HeaderRow )->enabled && row == -1 ) if ( QgsComposerTableStyle* style = mCellStyles.value( FirstColumn ) )
color = mCellStyles.value( HeaderRow )->cellBackgroundColor; if ( style->enabled && column == 0 )
if ( mCellStyles.value( FirstRow )->enabled && row == 0 ) color = style->cellBackgroundColor;
color = mCellStyles.value( FirstRow )->cellBackgroundColor; if ( QgsComposerTableStyle* style = mCellStyles.value( LastColumn ) )
if ( mCellStyles.value( LastRow )->enabled && row == mTableContents.count() - 1 ) if ( style->enabled && column == mColumns.count() - 1 )
color = mCellStyles.value( LastRow )->cellBackgroundColor; 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; return color;
} }

View File

@ -520,10 +520,13 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
newElement = relElement; newElement = relElement;
} }
if ( elem.hasAttribute( QStringLiteral( "showLabel" ) ) ) if ( newElement )
newElement->setShowLabel( elem.attribute( QStringLiteral( "showLabel" ) ).toInt() ); {
else if ( elem.hasAttribute( QStringLiteral( "showLabel" ) ) )
newElement->setShowLabel( true ); newElement->setShowLabel( elem.attribute( QStringLiteral( "showLabel" ) ).toInt() );
else
newElement->setShowLabel( true );
}
return newElement; return newElement;
} }

View File

@ -746,10 +746,17 @@ void QgsVectorLayerFeatureIterator::addVirtualAttributes( QgsFeature& f )
void QgsVectorLayerFeatureIterator::addExpressionAttribute( QgsFeature& f, int attrIndex ) void QgsVectorLayerFeatureIterator::addExpressionAttribute( QgsFeature& f, int attrIndex )
{ {
QgsExpression* exp = mExpressionFieldInfo.value( attrIndex ); QgsExpression* exp = mExpressionFieldInfo.value( attrIndex );
mExpressionContext->setFeature( f ); if ( exp )
QVariant val = exp->evaluate( mExpressionContext.data() ); {
mSource->mFields.at( attrIndex ).convertCompatible( val ); mExpressionContext->setFeature( f );
f.setAttribute( attrIndex, val ); 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 ) bool QgsVectorLayerFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )

View File

@ -948,6 +948,10 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh
myRasterRenderer = myPseudoColorRenderer; myRasterRenderer = myPseudoColorRenderer;
myMinMaxOrigin = myPseudoColorRenderer->minMaxOrigin(); myMinMaxOrigin = myPseudoColorRenderer->minMaxOrigin();
} }
else
{
return;
}
Q_FOREACH ( int myBand, myBands ) Q_FOREACH ( int myBand, myBands )
{ {

View File

@ -125,7 +125,8 @@ QStringList QgsRendererRegistry::renderersList( QgsRendererAbstractMetadata::Lay
QStringList renderers; QStringList renderers;
Q_FOREACH ( const QString& renderer, mRenderersOrder ) Q_FOREACH ( const QString& renderer, mRenderersOrder )
{ {
if ( mRenderers.value( renderer )->compatibleLayerTypes() & layerTypes ) QgsRendererAbstractMetadata* r = mRenderers.value( renderer );
if ( r && r->compatibleLayerTypes() & layerTypes )
renderers << renderer; renderers << renderer;
} }
return renderers; return renderers;

View File

@ -344,12 +344,8 @@ void QgsVariableEditorTree::refreshScopeVariables( QgsExpressionContextScope* sc
Q_FOREACH ( const QString& name, scope->filteredVariableNames() ) Q_FOREACH ( const QString& name, scope->filteredVariableNames() )
{ {
QTreeWidgetItem* item; QTreeWidgetItem* item = mVariableToItem.value( qMakePair( scopeIndex, name ) );
if ( mVariableToItem.contains( qMakePair( scopeIndex, name ) ) ) if ( !item )
{
item = mVariableToItem.value( qMakePair( scopeIndex, name ) );
}
else
{ {
item = new QTreeWidgetItem( scopeItem ); item = new QTreeWidgetItem( scopeItem );
mVariableToItem.insert( qMakePair( scopeIndex, name ), item ); mVariableToItem.insert( qMakePair( scopeIndex, name ), item );

View File

@ -858,6 +858,10 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData * data, Qt::DropAction )
QgsGrassObject vectorObject( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset(), destName, QgsGrassObject::Vector ); QgsGrassObject vectorObject( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset(), destName, QgsGrassObject::Vector );
import = new QgsGrassVectorImport( vectorProvider, vectorObject ); // takes provider ownership import = new QgsGrassVectorImport( vectorProvider, vectorObject ); // takes provider ownership
} }
else
{
return false;
}
connect( import, SIGNAL( finished( QgsGrassImport* ) ), SLOT( onImportFinished( QgsGrassImport* ) ) ); connect( import, SIGNAL( finished( QgsGrassImport* ) ), SLOT( onImportFinished( QgsGrassImport* ) ) );

View File

@ -2925,11 +2925,12 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
params.insert( QStringLiteral( "featureType" ), featureTypeName ); params.insert( QStringLiteral( "featureType" ), featureTypeName );
params.insert( QStringLiteral( "getFeatureInfoUrl" ), requestUrl.toString() ); params.insert( QStringLiteral( "getFeatureInfoUrl" ), requestUrl.toString() );
featureStore.setParams( params ); 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() ) if ( coordinateTransform.isValid() && feature->hasGeometry() )
{ {

View File

@ -1216,6 +1216,7 @@ void TestQgsGrassProvider::edit()
grassLayer->startEditing(); grassLayer->startEditing();
grassProvider->startEditing( grassLayer ); grassProvider->startEditing( grassLayer );
Q_ASSERT( expectedLayer );
expectedLayer->startEditing(); expectedLayer->startEditing();
} }
@ -1582,7 +1583,9 @@ bool TestQgsGrassProvider::compare( QMap<QString, QgsVectorLayer *> layers, bool
{ {
Q_FOREACH ( const QString & grassUri, layers.keys() ) 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 ); reportRow( "comparison failed: " + grassUri );
} }