Skip to content

Commit

Permalink
more coverity fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 7, 2015
1 parent e3d5a05 commit a3668f5
Show file tree
Hide file tree
Showing 35 changed files with 305 additions and 601 deletions.
1 change: 1 addition & 0 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -153,6 +153,7 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
break;
case opATAN:
leftMatrix.atangens();
break;
case opSIGN:
leftMatrix.changeSign();
break;
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/vector/qgsoverlayanalyzer.cpp
Expand Up @@ -31,14 +31,14 @@ bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* l
const QString& shapefileName, bool onlySelectedFeatures,
QProgressDialog* p )
{
if ( !layerA && !layerB )
if ( !layerA || !layerB )
{
return false;
}

QgsVectorDataProvider* dpA = layerA->dataProvider();
QgsVectorDataProvider* dpB = layerB->dataProvider();
if ( !dpA && !dpB )
QgsVectorDataProvider *dpA = layerA->dataProvider();
QgsVectorDataProvider *dpB = layerB->dataProvider();
if ( !dpA || !dpB )
{
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -87,7 +87,9 @@ class QgsComposerLegendMenuProvider : public QObject, public QgsLayerTreeViewMen



QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): QgsComposerItemBaseWidget( 0, legend ), mLegend( legend )
QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend )
: QgsComposerItemBaseWidget( 0, legend )
, mLegend( legend )
{
setupUi( this );

Expand All @@ -113,10 +115,9 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): Q
if ( legend )
{
connect( legend, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
mWrapCharLineEdit->setText( legend->wrapChar() );
}

mWrapCharLineEdit->setText( legend->wrapChar() );

setGuiElements();

connect( mItemTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
Expand Down
51 changes: 30 additions & 21 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -115,39 +115,48 @@ QList<QPair<QLabel*, QWidget*> > QgsVectorLayerSaveAsDialog::createControls( con
{
case QgsVectorFileWriter::Int:
{
QgsVectorFileWriter::IntOption* opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( option );
QSpinBox* sb = new QSpinBox();
sb->setObjectName( it.key() );
sb->setValue( opt->defaultValue );
control = sb;
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( option );
if ( opt )
{
QSpinBox *sb = new QSpinBox();
sb->setObjectName( it.key() );
sb->setValue( opt->defaultValue );
control = sb;
}
break;
}

case QgsVectorFileWriter::Set:
{
QgsVectorFileWriter::SetOption* opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( option );
QComboBox* cb = new QComboBox();
cb->setObjectName( it.key() );
Q_FOREACH ( const QString& val, opt->values )
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( option );
if ( opt )
{
cb->addItem( val, val );
QComboBox* cb = new QComboBox();
cb->setObjectName( it.key() );
Q_FOREACH ( const QString& val, opt->values )
{
cb->addItem( val, val );
}
if ( opt->allowNone )
cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) );
int idx = cb->findText( opt->defaultValue );
if ( idx == -1 )
idx = cb->findData( QVariant( QVariant::String ) );
cb->setCurrentIndex( idx );
control = cb;
}
if ( opt->allowNone )
cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) );
int idx = cb->findText( opt->defaultValue );
if ( idx == -1 )
idx = cb->findData( QVariant( QVariant::String ) );
cb->setCurrentIndex( idx );
control = cb;
break;
}

case QgsVectorFileWriter::String:
{
QgsVectorFileWriter::StringOption* opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( option );
QLineEdit* le = new QLineEdit( opt->defaultValue );
le->setObjectName( it.key() );
control = le;
QgsVectorFileWriter::StringOption *opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( option );
if ( opt )
{
QLineEdit* le = new QLineEdit( opt->defaultValue );
le->setObjectName( it.key() );
control = le;
}
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -1226,8 +1226,8 @@ void QgsPluginManager::on_buttonUninstall_clicked()

void QgsPluginManager::on_treeRepositories_itemSelectionChanged()
{
buttonEditRep->setEnabled( ! treeRepositories -> selectedItems().isEmpty() );
buttonDeleteRep->setEnabled( ! treeRepositories -> selectedItems().isEmpty() );
buttonEditRep->setEnabled( ! treeRepositories->selectedItems().isEmpty() );
buttonDeleteRep->setEnabled( ! treeRepositories->selectedItems().isEmpty() );
}


Expand Down
9 changes: 6 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -713,7 +713,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
QgsPythonRunner::run( "import pyplugin_installer" );
QgsPythonRunner::run( "pyplugin_installer.initPluginInstaller()" );
// enable Python in the Plugin Manager and pass the PythonUtils to it
mPluginManager -> setPythonUtils( mPythonUtils );
mPluginManager->setPythonUtils( mPythonUtils );
}
else
{
Expand Down Expand Up @@ -2988,13 +2988,16 @@ bool QgisApp::askUserForZipItemLayers( QString path )
foreach ( QgsDataItem* item, childItems )
{
QgsLayerItem *layerItem = dynamic_cast<QgsLayerItem *>( item );
if ( !layerItem )
continue;

QgsDebugMsg( QString( "item path=%1 provider=%2" ).arg( item->path() ).arg( layerItem->providerKey() ) );
if ( layerItem && layerItem->providerKey() == "gdal" )
if ( layerItem->providerKey() == "gdal" )
{
if ( addRasterLayer( item->path(), QFileInfo( item->name() ).completeBaseName() ) )
ok = true;
}
else if ( layerItem && layerItem->providerKey() == "ogr" )
else if ( layerItem->providerKey() == "ogr" )
{
if ( addVectorLayers( QStringList( item->path() ), "System", "file" ) )
ok = true;
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsaddattrdialog.cpp
Expand Up @@ -28,6 +28,9 @@ QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent, Qt:
{
setupUi( this );

if ( !vlayer )
return;

//fill data types into the combo box
const QList< QgsVectorDataProvider::NativeType > &typelist = vlayer->dataProvider()->nativeTypes();

Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -217,8 +217,11 @@ bool QgsAppLayerTreeViewMenuProvider::removeLegendLayerAction( QAction* action )

void QgsAppLayerTreeViewMenuProvider::addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer )
{
if ( !action || !layer )
return;

legendLayerActions( layer->type() );
if ( !action || !layer || ! mLegendLayerActionMap.contains( layer->type() ) )
if ( !mLegendLayerActionMap.contains( layer->type() ) )
return;

QMap< QgsMapLayer::LayerType, QList< LegendLayerAction > >::iterator it
Expand Down
33 changes: 20 additions & 13 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -80,20 +80,27 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const
if ( !labelFieldName.isEmpty() )
{
mCurLabelField = vlayer->fieldNameIndex( labelFieldName );
mLabelTextLineEdit->setText( attributeValues[mCurLabelField].toString() );
const QgsFields& layerFields = vlayer->pendingFields();
switch ( layerFields[mCurLabelField].type() )
if ( mCurLabelField >= 0 )
{
case QVariant::Double:
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
break;
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
mLabelTextLineEdit->setValidator( new QIntValidator( this ) );
break;
default:
break;
mLabelTextLineEdit->setText( attributeValues[mCurLabelField].toString() );
const QgsFields& layerFields = vlayer->pendingFields();
switch ( layerFields[mCurLabelField].type() )
{
case QVariant::Double:
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
break;
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
mLabelTextLineEdit->setValidator( new QIntValidator( this ) );
break;
default:
break;
}
}
else
{
mLabelTextLineEdit->setEnabled( false );
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -293,9 +293,12 @@ QgsVectorLayerProperties::~QgsVectorLayerProperties()

void QgsVectorLayerProperties::toggleEditing()
{
if ( !layer )
return;

emit toggleEditing( layer );

pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
pbnQueryBuilder->setEnabled( layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
if ( layer->isEditable() )
{
Expand Down Expand Up @@ -381,7 +384,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
// on the builder. If the ability to enter a query directly into the box is required,
// a mechanism to check it must be implemented.
txtSubsetSQL->setEnabled( false );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
pbnQueryBuilder->setEnabled( layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
if ( layer->isEditable() )
{
Expand All @@ -396,7 +399,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
fieldComboBox->addItem( myFields[idx].name() );
}

setDisplayField( layer-> displayField() );
setDisplayField( layer->displayField() );

// set up the scale based layer visibility stuff....
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
Expand Down
8 changes: 4 additions & 4 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -1069,11 +1069,11 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen

//since we are pasting items, clear the existing selection
setAllUnselected();
}

if ( pasteInPlace )
{
pasteInPlacePt = new QPointF( 0, pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
if ( pasteInPlace )
{
pasteInPlacePt = new QPointF( 0, pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
}
}
QDomNodeList composerLabelList = elem.elementsByTagName( "ComposerLabel" );
for ( int i = 0; i < composerLabelList.size(); ++i )
Expand Down
6 changes: 5 additions & 1 deletion src/core/composer/qgslegendmodel.cpp
Expand Up @@ -662,7 +662,6 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu

QDomNodeList topLevelItemList = legendModelElem.childNodes();
QDomElement currentElem;
QgsComposerLegendItem* currentItem = 0;

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

//toplevel items can be groups or layers
QgsComposerLegendItem* currentItem = 0;
if ( currentElem.tagName() == "LayerItem" )
{
currentItem = new QgsComposerLayerItem();
Expand All @@ -682,6 +682,10 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
{
currentItem = new QgsComposerGroupItem();
}

if ( !currentItem )
continue;

currentItem->readXML( currentElem, mHasTopLevelWindow );

QList<QStandardItem *> itemsList;
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/problem.cpp
Expand Up @@ -2352,7 +2352,7 @@ namespace pal
std::cout << "new_best" << std::endl;
#endif
best_cost = cur_cost;
memcpy( best_sol, sol, sizeof( int ) *subSize );
memcpy( best_sol, sol, sizeof( int ) * subSize );

stop_it = ( it + itwimp > maxit ? maxit : it + itwimp );
}
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsgml.cpp
Expand Up @@ -431,6 +431,7 @@ void QgsGml::endElement( const XML_Char* el )
else
{
QgsDebugMsg( "No wkb fragments" );
delete [] wkb;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -641,7 +641,7 @@ QList<QgsMapLayer*> QgsMapLayer::fromLayerDefinition( QDomDocument& document )

QString type = layerElem.attribute( "type" );
QgsDebugMsg( type );
QgsMapLayer *layer = NULL;
QgsMapLayer *layer = 0;

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

if ( !layer )
continue;

bool ok = layer->readLayerXML( layerElem );
if ( ok )
layers << layer;
Expand Down
12 changes: 5 additions & 7 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -2447,14 +2447,12 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
const QgsCoordinateTransform* ct, QString* errorMessage )
{
if ( !layer )
{
//return error
}
QgsFeatureRendererV2* renderer = layer->rendererV2();
return ErrInvalidLayer;

QgsFeatureRendererV2 *renderer = layer->rendererV2();
if ( !renderer )
{
//return error
}
return ErrInvalidLayer;

QHash< QgsSymbolV2*, QList<QgsFeature> > features;

//unit type
Expand Down
17 changes: 13 additions & 4 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2907,17 +2907,20 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
const QgsVectorJoinInfo* join = mJoinBuffer->joinForFieldIndex( index, mUpdatedFields, sourceLayerIndex );
Q_ASSERT( join );

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

return vl->dataProvider()->uniqueValues( sourceLayerIndex, uniqueValues, limit );
if ( vl )
vl->dataProvider()->uniqueValues( sourceLayerIndex, uniqueValues, limit );

return;
}
else if ( origin == QgsFields::OriginEdit || origin == QgsFields::OriginExpression )
{
// the layer is editable, but in certain cases it can still be avoided going through all features
if ( origin == QgsFields::OriginEdit && mEditBuffer->mDeletedFeatureIds.isEmpty() && mEditBuffer->mAddedFeatures.isEmpty() && !mEditBuffer->mDeletedAttributeIds.contains( index ) && mEditBuffer->mChangedAttributeValues.isEmpty() )
{
return mDataProvider->uniqueValues( index, uniqueValues, limit );
mDataProvider->uniqueValues( index, uniqueValues, limit );
return;
}

// we need to go through each feature
Expand Down Expand Up @@ -3608,10 +3611,16 @@ void QgsVectorLayer::onRelationsLoaded()
if ( elem->type() == QgsAttributeEditorElement::AeTypeContainer )
{
QgsAttributeEditorContainer* cont = dynamic_cast< QgsAttributeEditorContainer* >( elem );
if ( !cont )
continue;

QList<QgsAttributeEditorElement*> relations = cont->findElements( QgsAttributeEditorElement::AeTypeRelation );
Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
{
QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
if ( !rel )
continue;

rel->init( QgsProject::instance()->relationManager() );
}
}
Expand Down

0 comments on commit a3668f5

Please sign in to comment.