Skip to content

Commit a3668f5

Browse files
committed
more coverity fixes
1 parent e3d5a05 commit a3668f5

35 files changed

+305
-601
lines changed

src/analysis/raster/qgsrastercalcnode.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
153153
break;
154154
case opATAN:
155155
leftMatrix.atangens();
156+
break;
156157
case opSIGN:
157158
leftMatrix.changeSign();
158159
break;

src/analysis/vector/qgsoverlayanalyzer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* l
3131
const QString& shapefileName, bool onlySelectedFeatures,
3232
QProgressDialog* p )
3333
{
34-
if ( !layerA && !layerB )
34+
if ( !layerA || !layerB )
3535
{
3636
return false;
3737
}
3838

39-
QgsVectorDataProvider* dpA = layerA->dataProvider();
40-
QgsVectorDataProvider* dpB = layerB->dataProvider();
41-
if ( !dpA && !dpB )
39+
QgsVectorDataProvider *dpA = layerA->dataProvider();
40+
QgsVectorDataProvider *dpB = layerB->dataProvider();
41+
if ( !dpA || !dpB )
4242
{
4343
return false;
4444
}

src/app/composer/qgscomposerlegendwidget.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ class QgsComposerLegendMenuProvider : public QObject, public QgsLayerTreeViewMen
8787

8888

8989

90-
QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): QgsComposerItemBaseWidget( 0, legend ), mLegend( legend )
90+
QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend )
91+
: QgsComposerItemBaseWidget( 0, legend )
92+
, mLegend( legend )
9193
{
9294
setupUi( this );
9395

@@ -113,10 +115,9 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): Q
113115
if ( legend )
114116
{
115117
connect( legend, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
118+
mWrapCharLineEdit->setText( legend->wrapChar() );
116119
}
117120

118-
mWrapCharLineEdit->setText( legend->wrapChar() );
119-
120121
setGuiElements();
121122

122123
connect( mItemTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),

src/app/ogr/qgsvectorlayersaveasdialog.cpp

+30-21
Original file line numberDiff line numberDiff line change
@@ -115,39 +115,48 @@ QList<QPair<QLabel*, QWidget*> > QgsVectorLayerSaveAsDialog::createControls( con
115115
{
116116
case QgsVectorFileWriter::Int:
117117
{
118-
QgsVectorFileWriter::IntOption* opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( option );
119-
QSpinBox* sb = new QSpinBox();
120-
sb->setObjectName( it.key() );
121-
sb->setValue( opt->defaultValue );
122-
control = sb;
118+
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( option );
119+
if ( opt )
120+
{
121+
QSpinBox *sb = new QSpinBox();
122+
sb->setObjectName( it.key() );
123+
sb->setValue( opt->defaultValue );
124+
control = sb;
125+
}
123126
break;
124127
}
125128

126129
case QgsVectorFileWriter::Set:
127130
{
128-
QgsVectorFileWriter::SetOption* opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( option );
129-
QComboBox* cb = new QComboBox();
130-
cb->setObjectName( it.key() );
131-
Q_FOREACH ( const QString& val, opt->values )
131+
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( option );
132+
if ( opt )
132133
{
133-
cb->addItem( val, val );
134+
QComboBox* cb = new QComboBox();
135+
cb->setObjectName( it.key() );
136+
Q_FOREACH ( const QString& val, opt->values )
137+
{
138+
cb->addItem( val, val );
139+
}
140+
if ( opt->allowNone )
141+
cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) );
142+
int idx = cb->findText( opt->defaultValue );
143+
if ( idx == -1 )
144+
idx = cb->findData( QVariant( QVariant::String ) );
145+
cb->setCurrentIndex( idx );
146+
control = cb;
134147
}
135-
if ( opt->allowNone )
136-
cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) );
137-
int idx = cb->findText( opt->defaultValue );
138-
if ( idx == -1 )
139-
idx = cb->findData( QVariant( QVariant::String ) );
140-
cb->setCurrentIndex( idx );
141-
control = cb;
142148
break;
143149
}
144150

145151
case QgsVectorFileWriter::String:
146152
{
147-
QgsVectorFileWriter::StringOption* opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( option );
148-
QLineEdit* le = new QLineEdit( opt->defaultValue );
149-
le->setObjectName( it.key() );
150-
control = le;
153+
QgsVectorFileWriter::StringOption *opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( option );
154+
if ( opt )
155+
{
156+
QLineEdit* le = new QLineEdit( opt->defaultValue );
157+
le->setObjectName( it.key() );
158+
control = le;
159+
}
151160
break;
152161
}
153162

src/app/pluginmanager/qgspluginmanager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,8 @@ void QgsPluginManager::on_buttonUninstall_clicked()
12261226

12271227
void QgsPluginManager::on_treeRepositories_itemSelectionChanged()
12281228
{
1229-
buttonEditRep->setEnabled( ! treeRepositories -> selectedItems().isEmpty() );
1230-
buttonDeleteRep->setEnabled( ! treeRepositories -> selectedItems().isEmpty() );
1229+
buttonEditRep->setEnabled( ! treeRepositories->selectedItems().isEmpty() );
1230+
buttonDeleteRep->setEnabled( ! treeRepositories->selectedItems().isEmpty() );
12311231
}
12321232

12331233

src/app/qgisapp.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
713713
QgsPythonRunner::run( "import pyplugin_installer" );
714714
QgsPythonRunner::run( "pyplugin_installer.initPluginInstaller()" );
715715
// enable Python in the Plugin Manager and pass the PythonUtils to it
716-
mPluginManager -> setPythonUtils( mPythonUtils );
716+
mPluginManager->setPythonUtils( mPythonUtils );
717717
}
718718
else
719719
{
@@ -2988,13 +2988,16 @@ bool QgisApp::askUserForZipItemLayers( QString path )
29882988
foreach ( QgsDataItem* item, childItems )
29892989
{
29902990
QgsLayerItem *layerItem = dynamic_cast<QgsLayerItem *>( item );
2991+
if ( !layerItem )
2992+
continue;
2993+
29912994
QgsDebugMsg( QString( "item path=%1 provider=%2" ).arg( item->path() ).arg( layerItem->providerKey() ) );
2992-
if ( layerItem && layerItem->providerKey() == "gdal" )
2995+
if ( layerItem->providerKey() == "gdal" )
29932996
{
29942997
if ( addRasterLayer( item->path(), QFileInfo( item->name() ).completeBaseName() ) )
29952998
ok = true;
29962999
}
2997-
else if ( layerItem && layerItem->providerKey() == "ogr" )
3000+
else if ( layerItem->providerKey() == "ogr" )
29983001
{
29993002
if ( addVectorLayers( QStringList( item->path() ), "System", "file" ) )
30003003
ok = true;

src/app/qgsaddattrdialog.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent, Qt:
2828
{
2929
setupUi( this );
3030

31+
if ( !vlayer )
32+
return;
33+
3134
//fill data types into the combo box
3235
const QList< QgsVectorDataProvider::NativeType > &typelist = vlayer->dataProvider()->nativeTypes();
3336

src/app/qgsapplayertreeviewmenuprovider.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ bool QgsAppLayerTreeViewMenuProvider::removeLegendLayerAction( QAction* action )
217217

218218
void QgsAppLayerTreeViewMenuProvider::addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer )
219219
{
220+
if ( !action || !layer )
221+
return;
222+
220223
legendLayerActions( layer->type() );
221-
if ( !action || !layer || ! mLegendLayerActionMap.contains( layer->type() ) )
224+
if ( !mLegendLayerActionMap.contains( layer->type() ) )
222225
return;
223226

224227
QMap< QgsMapLayer::LayerType, QList< LegendLayerAction > >::iterator it

src/app/qgslabelpropertydialog.cpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,27 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const
8080
if ( !labelFieldName.isEmpty() )
8181
{
8282
mCurLabelField = vlayer->fieldNameIndex( labelFieldName );
83-
mLabelTextLineEdit->setText( attributeValues[mCurLabelField].toString() );
84-
const QgsFields& layerFields = vlayer->pendingFields();
85-
switch ( layerFields[mCurLabelField].type() )
83+
if ( mCurLabelField >= 0 )
8684
{
87-
case QVariant::Double:
88-
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
89-
break;
90-
case QVariant::Int:
91-
case QVariant::UInt:
92-
case QVariant::LongLong:
93-
mLabelTextLineEdit->setValidator( new QIntValidator( this ) );
94-
break;
95-
default:
96-
break;
85+
mLabelTextLineEdit->setText( attributeValues[mCurLabelField].toString() );
86+
const QgsFields& layerFields = vlayer->pendingFields();
87+
switch ( layerFields[mCurLabelField].type() )
88+
{
89+
case QVariant::Double:
90+
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
91+
break;
92+
case QVariant::Int:
93+
case QVariant::UInt:
94+
case QVariant::LongLong:
95+
mLabelTextLineEdit->setValidator( new QIntValidator( this ) );
96+
break;
97+
default:
98+
break;
99+
}
100+
}
101+
else
102+
{
103+
mLabelTextLineEdit->setEnabled( false );
97104
}
98105
}
99106
}

src/app/qgsvectorlayerproperties.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,12 @@ QgsVectorLayerProperties::~QgsVectorLayerProperties()
293293

294294
void QgsVectorLayerProperties::toggleEditing()
295295
{
296+
if ( !layer )
297+
return;
298+
296299
emit toggleEditing( layer );
297300

298-
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
301+
pbnQueryBuilder->setEnabled( layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
299302
!layer->isEditable() && layer->vectorJoins().size() < 1 );
300303
if ( layer->isEditable() )
301304
{
@@ -381,7 +384,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
381384
// on the builder. If the ability to enter a query directly into the box is required,
382385
// a mechanism to check it must be implemented.
383386
txtSubsetSQL->setEnabled( false );
384-
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
387+
pbnQueryBuilder->setEnabled( layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
385388
!layer->isEditable() && layer->vectorJoins().size() < 1 );
386389
if ( layer->isEditable() )
387390
{
@@ -396,7 +399,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
396399
fieldComboBox->addItem( myFields[idx].name() );
397400
}
398401

399-
setDisplayField( layer-> displayField() );
402+
setDisplayField( layer->displayField() );
400403

401404
// set up the scale based layer visibility stuff....
402405
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales

src/core/composer/qgscomposition.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,11 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
10691069

10701070
//since we are pasting items, clear the existing selection
10711071
setAllUnselected();
1072-
}
10731072

1074-
if ( pasteInPlace )
1075-
{
1076-
pasteInPlacePt = new QPointF( 0, pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1073+
if ( pasteInPlace )
1074+
{
1075+
pasteInPlacePt = new QPointF( 0, pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1076+
}
10771077
}
10781078
QDomNodeList composerLabelList = elem.elementsByTagName( "ComposerLabel" );
10791079
for ( int i = 0; i < composerLabelList.size(); ++i )

src/core/composer/qgslegendmodel.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
662662

663663
QDomNodeList topLevelItemList = legendModelElem.childNodes();
664664
QDomElement currentElem;
665-
QgsComposerLegendItem* currentItem = 0;
666665

667666
int nTopLevelItems = topLevelItemList.size();
668667
for ( int i = 0; i < nTopLevelItems; ++i )
@@ -674,6 +673,7 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
674673
}
675674

676675
//toplevel items can be groups or layers
676+
QgsComposerLegendItem* currentItem = 0;
677677
if ( currentElem.tagName() == "LayerItem" )
678678
{
679679
currentItem = new QgsComposerLayerItem();
@@ -682,6 +682,10 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
682682
{
683683
currentItem = new QgsComposerGroupItem();
684684
}
685+
686+
if ( !currentItem )
687+
continue;
688+
685689
currentItem->readXML( currentElem, mHasTopLevelWindow );
686690

687691
QList<QStandardItem *> itemsList;

src/core/pal/problem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ namespace pal
23522352
std::cout << "new_best" << std::endl;
23532353
#endif
23542354
best_cost = cur_cost;
2355-
memcpy( best_sol, sol, sizeof( int ) *subSize );
2355+
memcpy( best_sol, sol, sizeof( int ) * subSize );
23562356

23572357
stop_it = ( it + itwimp > maxit ? maxit : it + itwimp );
23582358
}

src/core/qgsgml.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ void QgsGml::endElement( const XML_Char* el )
431431
else
432432
{
433433
QgsDebugMsg( "No wkb fragments" );
434+
delete [] wkb;
434435
}
435436
}
436437
}

src/core/qgsmaplayer.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ QList<QgsMapLayer*> QgsMapLayer::fromLayerDefinition( QDomDocument& document )
641641

642642
QString type = layerElem.attribute( "type" );
643643
QgsDebugMsg( type );
644-
QgsMapLayer *layer = NULL;
644+
QgsMapLayer *layer = 0;
645645

646646
if ( type == "vector" )
647647
{
@@ -657,6 +657,9 @@ QList<QgsMapLayer*> QgsMapLayer::fromLayerDefinition( QDomDocument& document )
657657
layer = QgsPluginLayerRegistry::instance()->createLayer( typeName );
658658
}
659659

660+
if ( !layer )
661+
continue;
662+
660663
bool ok = layer->readLayerXML( layerElem );
661664
if ( ok )
662665
layers << layer;

src/core/qgsvectorfilewriter.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -2447,14 +2447,12 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
24472447
const QgsCoordinateTransform* ct, QString* errorMessage )
24482448
{
24492449
if ( !layer )
2450-
{
2451-
//return error
2452-
}
2453-
QgsFeatureRendererV2* renderer = layer->rendererV2();
2450+
return ErrInvalidLayer;
2451+
2452+
QgsFeatureRendererV2 *renderer = layer->rendererV2();
24542453
if ( !renderer )
2455-
{
2456-
//return error
2457-
}
2454+
return ErrInvalidLayer;
2455+
24582456
QHash< QgsSymbolV2*, QList<QgsFeature> > features;
24592457

24602458
//unit type

src/core/qgsvectorlayer.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -2907,17 +2907,20 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
29072907
const QgsVectorJoinInfo* join = mJoinBuffer->joinForFieldIndex( index, mUpdatedFields, sourceLayerIndex );
29082908
Q_ASSERT( join );
29092909

2910-
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( join->joinLayerId ) );
2911-
Q_ASSERT( vl );
2910+
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( join->joinLayerId ) );
29122911

2913-
return vl->dataProvider()->uniqueValues( sourceLayerIndex, uniqueValues, limit );
2912+
if ( vl )
2913+
vl->dataProvider()->uniqueValues( sourceLayerIndex, uniqueValues, limit );
2914+
2915+
return;
29142916
}
29152917
else if ( origin == QgsFields::OriginEdit || origin == QgsFields::OriginExpression )
29162918
{
29172919
// the layer is editable, but in certain cases it can still be avoided going through all features
29182920
if ( origin == QgsFields::OriginEdit && mEditBuffer->mDeletedFeatureIds.isEmpty() && mEditBuffer->mAddedFeatures.isEmpty() && !mEditBuffer->mDeletedAttributeIds.contains( index ) && mEditBuffer->mChangedAttributeValues.isEmpty() )
29192921
{
2920-
return mDataProvider->uniqueValues( index, uniqueValues, limit );
2922+
mDataProvider->uniqueValues( index, uniqueValues, limit );
2923+
return;
29212924
}
29222925

29232926
// we need to go through each feature
@@ -3608,10 +3611,16 @@ void QgsVectorLayer::onRelationsLoaded()
36083611
if ( elem->type() == QgsAttributeEditorElement::AeTypeContainer )
36093612
{
36103613
QgsAttributeEditorContainer* cont = dynamic_cast< QgsAttributeEditorContainer* >( elem );
3614+
if ( !cont )
3615+
continue;
3616+
36113617
QList<QgsAttributeEditorElement*> relations = cont->findElements( QgsAttributeEditorElement::AeTypeRelation );
36123618
Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
36133619
{
36143620
QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
3621+
if ( !rel )
3622+
continue;
3623+
36153624
rel->init( QgsProject::instance()->relationManager() );
36163625
}
36173626
}

0 commit comments

Comments
 (0)