Skip to content
Permalink
Browse files

fix some coverity issues

  • Loading branch information
jef-n committed Feb 6, 2015
1 parent e0116ef commit e3d5a0549cb76cb750ba75dac5ffe21afa572a99
@@ -207,12 +207,14 @@ static void dumpBacktrace( unsigned int depth )
close( STDERR_FILENO ); // close stderr

// stderr to pipe
if ( dup( fd[1] ) != STDERR_FILENO )
int stderr_new = dup( fd[1] );
if ( stderr_new != STDERR_FILENO )
{
close( stderr_new );
QgsDebugMsg( "dup to stderr failed" );
}

close( fd[1] ); // close duped pipe
close( fd[1] ); // close duped pipe
}

void **buffer = new void *[ depth ];
@@ -552,7 +552,9 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
}
}
}
delete oldWidget;

if ( mRendererWidget != oldWidget )
delete oldWidget;

if ( mHistogramWidget )
{
@@ -911,6 +913,10 @@ void QgsRasterLayerProperties::apply()
{
resampleFilter->setZoomedOutResampler( zoomedOutResampler );
}
else
{
delete zoomedOutResampler;
}

if ( resampleFilter )
{
@@ -240,8 +240,11 @@ void QgsComposition::refreshItems()
void QgsComposition::setSelectedItem( QgsComposerItem *item )
{
setAllUnselected();
item->setSelected( true );
emit selectedItemChanged( item );
if ( item )
{
item->setSelected( true );
emit selectedItemChanged( item );
}
}

void QgsComposition::setAllUnselected()
@@ -105,7 +105,6 @@ namespace pal
x = new double[nbPoints];
y = new double[nbPoints];


for ( i = 0; i < nbPoints; i++ )
{
x[i] = ps.x[i];
@@ -115,6 +114,7 @@ namespace pal
if ( ps.cHull )
{
cHullSize = ps.cHullSize;
cHull = new int[cHullSize];
for ( i = 0; i < cHullSize; i++ )
{
cHull[i] = ps.cHull[i];
@@ -46,7 +46,6 @@ QgsColorSchemeRegistry *QgsColorSchemeRegistry::instance()

QgsColorSchemeRegistry::QgsColorSchemeRegistry()
{

}

QgsColorSchemeRegistry::~QgsColorSchemeRegistry()
@@ -1625,7 +1625,11 @@ QgsExpression::NodeBinaryOperator* QgsOgcUtils::nodeBinaryOperatorFromOgcFilter(
return NULL;
}

return dynamic_cast< QgsExpression::NodeBinaryOperator * >( expr );
QgsExpression::NodeBinaryOperator *ret = dynamic_cast< QgsExpression::NodeBinaryOperator * >( expr );
if ( !ret )
delete expr;

return ret;
}


@@ -1652,7 +1656,7 @@ QgsExpression::NodeFunction* QgsOgcUtils::nodeSpatialOperatorFromOgcFilter( QDom
}
else
{
errorMessage = QString( "No OGC Geometry found" );
errorMessage = "No OGC Geometry found";
delete gml2Args;
return NULL;
}
@@ -55,6 +55,7 @@ class GUI_EXPORT QgsAttributeEditorContext
, mLayer( 0 )
, mVectorLayerTools( 0 )
, mRelationMode( Undefined )
, mFormMode( Embed )
{}

QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, FormMode formMode )
@@ -264,19 +264,16 @@ void QgsGrassAttributes::updateAttributes()

QgsDebugMsg( QString( "sql: %1" ).arg( sql ) );

QString *error = mProvider->updateAttributes( tb->item( 0, 1 )->text().toInt(), tb->item( 1, 1 )->text().toInt(), sql );

if ( !error->isEmpty() )
QString error = mProvider->updateAttributes( tb->item( 0, 1 )->text().toInt(), tb->item( 1, 1 )->text().toInt(), sql );
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ), *error );
QMessageBox::warning( 0, tr( "Warning" ), error );
resultLabel->setText( tr( "ERROR" ) );
}
else
{
resultLabel->setText( tr( "OK" ) );
}

delete error;
}
}

@@ -568,9 +568,8 @@ void QgsGrassEdit::setAttributeTable( int field )
{
mAttributeTable->setRowCount( 0 );

QString *key = mProvider->key( field );

if ( !key->isEmpty() ) // Database link defined
QString key = mProvider->key( field );
if ( !key.isEmpty() ) // Database link defined
{
QVector<QgsField> *cols = mProvider->columns( field );

@@ -596,6 +595,8 @@ void QgsGrassEdit::setAttributeTable( int field )
ti->setFlags( ti->flags() & ~Qt::ItemIsEnabled );
mAttributeTable->setItem( c, 2, ti );
}

delete cols;
}
else
{
@@ -687,11 +688,10 @@ void QgsGrassEdit::alterTable( void )
}
}

QString *error = mProvider->createTable( field, mAttributeTable->item( 0, 0 )->text(), sql );

if ( !error->isEmpty() )
QString error = mProvider->createTable( field, mAttributeTable->item( 0, 0 )->text(), sql );
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ), *error );
QMessageBox::warning( 0, tr( "Warning" ), error );
}
else
{
@@ -700,7 +700,6 @@ void QgsGrassEdit::alterTable( void )
str.sprintf( "%d", field );
mFieldBox->addItem( str );
}
delete error;
}
else
{
@@ -719,13 +718,11 @@ void QgsGrassEdit::alterTable( void )
sql.append( " (" + mAttributeTable->item( i, 2 )->text() + ")" );
}

QString *error = mProvider->addColumn( field, sql );

if ( !error->isEmpty() )
QString error = mProvider->addColumn( field, sql );
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ), *error );
QMessageBox::warning( 0, tr( "Warning" ), error );
}
delete error;
}
}

@@ -1084,21 +1081,18 @@ int QgsGrassEdit::writeLine( int type, struct line_pnts *Points )
Vect_cat_set( mCats, field, cat );

// Insert new DB record if link is defined and the record for this cat does not exist
QString *key = mProvider->key( field );

if ( !key->isEmpty() ) // Database link defined
QString key = mProvider->key( field );
if ( !key.isEmpty() ) // Database link defined
{
QgsAttributeMap *atts = mProvider->attributes( field, cat );

if ( atts->count() == 0 ) // Nothing selected
{
QString *error = mProvider->insertAttributes( field, cat );

if ( !error->isEmpty() )
QString error = mProvider->insertAttributes( field, cat );
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ), *error );
QMessageBox::warning( 0, tr( "Warning" ), error );
}
delete error;
}

delete atts;
@@ -1411,14 +1405,15 @@ void QgsGrassEdit::checkOrphan( int field, int cat )
QgsDebugMsg( QString( "field = %1 cat = %2" ).arg( field ).arg( cat ) );

int orphan;
QString *error = mProvider->isOrphan( field, cat, &orphan );
QString error = mProvider->isOrphan( field, cat, orphan );

if ( !error->isEmpty() )
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ),
tr( "Cannot check orphan record: %1" ).arg( *error ) );
tr( "Cannot check orphan record: %1" ).arg( error ) );
return;
}

if ( !orphan )
return;

@@ -1432,35 +1427,35 @@ void QgsGrassEdit::checkOrphan( int field, int cat )

// Delete record
error = mProvider->deleteAttribute( field, cat );
if ( !error->isEmpty() )
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot delete orphan record: " )
+ *error );
+ error );
return;
}
}

void QgsGrassEdit::addAttributes( int field, int cat )
{
QString *key = mProvider->key( field );
QString key = mProvider->key( field );

QString lab;
lab.sprintf( "%d:%d", field, cat );
int tab = mAttributes->addTab( lab );
mAttributes->setField( tab, field );

QString catLabel;
if ( key->isEmpty() )
if ( key.isEmpty() )
{
catLabel = "Category";
}
else
{
catLabel = *key;
catLabel = key;
}
mAttributes->setCat( tab, catLabel, cat );

if ( !key->isEmpty() ) // Database link defined
if ( !key.isEmpty() ) // Database link defined
{
QVector<QgsField> *cols = mProvider->columns( field );

@@ -1486,7 +1481,7 @@ void QgsGrassEdit::addAttributes( int field, int cat )
QVariant att = ( *atts )[j];
QgsDebugMsg( QString( " name = %1" ).arg( col.name() ) );

if ( col.name() != *key )
if ( col.name() != key )
{
QgsDebugMsg( QString( " value = %1" ).arg( att.toString() ) );
mAttributes->addAttribute( tab, col.name(), att.toString(), col.typeName() );
@@ -1519,21 +1514,18 @@ void QgsGrassEdit::addCat( int line )
increaseMaxCat();

// Insert new DB record if link is defined and the record for this cat does not exist
QString *key = mProvider->key( field );

if ( !key->isEmpty() ) // Database link defined
QString key = mProvider->key( field );
if ( !key.isEmpty() ) // Database link defined
{
QgsAttributeMap *atts = mProvider->attributes( field, cat );

if ( atts->size() == 0 ) // Nothing selected
{
QString *error = mProvider->insertAttributes( field, cat );

if ( !error->isEmpty() )
QString error = mProvider->insertAttributes( field, cat );
if ( !error.isEmpty() )
{
QMessageBox::warning( 0, tr( "Warning" ), *error );
QMessageBox::warning( 0, tr( "Warning" ), error );
}
delete error;
}

delete atts;
@@ -2780,7 +2780,8 @@ void QgsGrassModuleInput::updateQgisLayers()
if ( item )
{
QgsGrassModuleInput *mapInput = dynamic_cast<QgsGrassModuleInput *>( item );
sourceMap = mapInput->currentMap();
if ( mapInput )
sourceMap = mapInput->currentMap();
}
}

@@ -178,7 +178,7 @@ bool BlockArray::setHistorySize( size_t newsize )

if ( !size )
{
FILE* tmp = tmpfile();
FILE *tmp = tmpfile();
if ( !tmp )
{
perror( "konsole: cannot open temp file.\n" );
@@ -189,9 +189,10 @@ bool BlockArray::setHistorySize( size_t newsize )
if ( ion < 0 )
{
perror( "konsole: cannot dup temp file.\n" );
fclose( tmp );
}
fclose( tmp );
}

if ( ion < 0 )
return false;

@@ -281,7 +281,7 @@ void HistoryScrollFile::addLine( bool previousWrapped )
// History Scroll Buffer //////////////////////////////////////
HistoryScrollBuffer::HistoryScrollBuffer( unsigned int maxLineCount )
: HistoryScroll( new HistoryTypeBuffer( maxLineCount ) )
, _historyBuffer()
, _historyBuffer( 0 )
, _maxLineCount( 0 )
, _usedLines( 0 )
, _head( 0 )
@@ -354,7 +354,6 @@ ErrorList topolTest::checkDuplicates( double tolerance, QgsVectorLayer *layer1,

QgsGeometry* canvasExtentPoly = QgsGeometry::fromWkt( theQgsInterface->mapCanvas()->extent().asWktPolygon() );


QMap<QgsFeatureId, FeatureLayer>::Iterator it;
QMap<QgsFeatureId, FeatureLayer>::ConstIterator FeatureListEnd = mFeatureMap2.end();
for ( it = mFeatureMap2.begin(); it != FeatureListEnd; ++it )
@@ -457,14 +456,13 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
return errorList;
}

QList<QgsFeatureId>* duplicateIds = new QList<QgsFeatureId>();

QgsSpatialIndex* index;
index = mLayerIndexes[layer1->id()];
QList<QgsFeatureId> *duplicateIds = new QList<QgsFeatureId>();

QgsSpatialIndex* index = mLayerIndexes[layer1->id()];
if ( !index )
{
qDebug() << "no index present";
delete duplicateIds;
return errorList;
}

@@ -567,6 +565,8 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
delete canvasExtentPoly;
}

delete duplicateIds;

return errorList;
}

@@ -280,5 +280,7 @@ static int cell_draw( char *name,
}

G_close_cell( cellfile );
fclose( fo );

return ( 0 );
}

1 comment on commit e3d5a05

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson commented on e3d5a05 Feb 6, 2015

@jef-n nice, thanks for this... The list was rather daunting!

Please sign in to comment.
You can’t perform that action at this time.