Skip to content

Commit

Permalink
Coverity fixes - unchecked return value
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 14, 2015
1 parent 8c16daf commit 0080f9e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 38 deletions.
11 changes: 8 additions & 3 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -160,6 +160,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
QgsRasterMatrix resultMatrix;

//read / write line by line
bool encounteredError = false;
for ( int i = 0; i < mNumOutputRows; ++i )
{
if ( p )
Expand All @@ -178,7 +179,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
{
double sourceTransformation[6];
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation );
if ( !GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation ) )
{
encounteredError = true;
break;
}
//the function readRasterPart calls GDALRasterIO (and ev. does some conversion if raster transformations are not the same)
readRasterPart( targetGeoTransform, 0, i, mNumOutputColumns, 1, sourceTransformation, sourceRasterBand, bufferIt.value()->data() );
}
Expand Down Expand Up @@ -244,11 +249,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
GDALClose( *datasetIt );
}

if ( p && p->wasCanceled() )
if (( p && p->wasCanceled() ) || encounteredError )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
return 3;
return encounteredError ? 1 : 3;
}
GDALClose( outputDataset );
CPLFree( resultScanLine );
Expand Down
10 changes: 4 additions & 6 deletions src/app/qgscustomprojectiondialog.cpp
Expand Up @@ -161,9 +161,8 @@ bool QgsCustomProjectionDialog::deleteCRS( QString id )
Q_ASSERT( myResult == SQLITE_OK );
}
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
sqlite3_step( myPreparedStatement );
// XXX Need to free memory from the error msg if one is set
if ( myResult != SQLITE_OK )
if ( myResult != SQLITE_OK || sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
{
QgsDebugMsg( QString( "failed to remove CRS from database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
}
Expand Down Expand Up @@ -218,11 +217,11 @@ void QgsCustomProjectionDialog::insertProjection( QString myProjectionAcronym )
+ ")"
;
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.length(), &myPreparedStatement, &myTail );
sqlite3_step( myPreparedStatement );
if ( myResult != SQLITE_OK )
if ( myResult != SQLITE_OK || sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
{
QgsDebugMsg( QString( "Update or insert failed in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
}

sqlite3_finalize( myPreparedStatement );
}

Expand Down Expand Up @@ -279,9 +278,8 @@ bool QgsCustomProjectionDialog::saveCRS( QgsCoordinateReferenceSystem myCRS, QSt
Q_ASSERT( myResult == SQLITE_OK );
}
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
sqlite3_step( myPreparedStatement );
// XXX Need to free memory from the error msg if one is set
if ( myResult != SQLITE_OK )
if ( myResult != SQLITE_OK || sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
{
QgsDebugMsg( QString( "failed to write to database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
}
Expand Down
12 changes: 5 additions & 7 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1512,13 +1512,12 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )
}
QgsDebugMsg( QString( "Update or insert sql \n%1" ).arg( mySql ) );
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
sqlite3_step( myPreparedStatement );

QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );

qint64 return_id;
if ( myResult == SQLITE_OK )
if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
{
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );

return_id = sqlite3_last_insert_rowid( myDatabase );
setInternalId( return_id );

Expand Down Expand Up @@ -1716,14 +1715,13 @@ int QgsCoordinateReferenceSystem::syncDb()
{
qCritical( "Could not begin transaction: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
return -1;

}

// fix up database, if not done already //
if ( sqlite3_exec( database, "alter table tbl_srs add noupdate boolean", 0, 0, 0 ) == SQLITE_OK )
sqlite3_exec( database, "update tbl_srs set noupdate=(auth_name='EPSG' and auth_id in (5513,5514,5221,2065,102067,4156,4818))", 0, 0, 0 );
( void )sqlite3_exec( database, "update tbl_srs set noupdate=(auth_name='EPSG' and auth_id in (5513,5514,5221,2065,102067,4156,4818))", 0, 0, 0 );

sqlite3_exec( database, "UPDATE tbl_srs SET srid=141001 WHERE srid=41001 AND auth_name='OSGEO' AND auth_id='41001'", 0, 0, 0 );
( void )sqlite3_exec( database, "UPDATE tbl_srs SET srid=141001 WHERE srid=41001 AND auth_name='OSGEO' AND auth_id='41001'", 0, 0, 0 );

OGRSpatialReferenceH crs = OSRNewSpatialReference( NULL );
const char *tail;
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -620,7 +620,7 @@ int QgsStyleV2::addGroup( QString groupName, int parentid )
sqlite3_stmt *ppStmt;
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK )
sqlite3_step( ppStmt );
( void )sqlite3_step( ppStmt );

sqlite3_finalize( ppStmt );

Expand All @@ -636,7 +636,7 @@ int QgsStyleV2::addTag( QString tagname )
char *query = sqlite3_mprintf( "INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK )
sqlite3_step( ppStmt );
( void )sqlite3_step( ppStmt );
sqlite3_finalize( ppStmt );

return ( int )sqlite3_last_insert_rowid( mCurrentDB );
Expand Down
14 changes: 3 additions & 11 deletions src/gui/qgsprojectionselector.cpp
Expand Up @@ -581,22 +581,14 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
showDBMissingWarning( mSrsDatabaseFileName );
return;
}
// prepare the sql statement

const char *tail;
sqlite3_stmt *stmt;
// get total count of records in the projection table
QString sql = "select count(*) from tbl_srs";

rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
Q_ASSERT( rc == SQLITE_OK );
sqlite3_step( stmt );
sqlite3_finalize( stmt );

// Set up the query to retrieve the projection information needed to populate the list
//note I am giving the full field names for clarity here and in case someone
//changes the underlying view TS
sql = QString( "select description, srs_id, upper(auth_name||':'||auth_id), is_geo, name, parameters, deprecated from vw_srs where %1 order by name,description" )
.arg( sqlFilter );
QString sql = QString( "select description, srs_id, upper(auth_name||':'||auth_id), is_geo, name, parameters, deprecated from vw_srs where %1 order by name,description" )
.arg( sqlFilter );

rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
// XXX Need to free memory from the error msg if one is set
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Expand Up @@ -71,7 +71,7 @@ QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLay

void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
if ( layer && layer->layerType() != "EllipseMarker" )
if ( !layer || layer->layerType() != "EllipseMarker" )
{
return;
}
Expand Down
Expand Up @@ -478,7 +478,7 @@ void eVisDatabaseConnectionGui::on_pbtnRunQuery_clicked()
else if ( myResults->isSelect() )
{
//if valid and a select query, save results into temporary file and load as layer
myResults->next();
( void )myResults->next();
if ( myResults->isValid() )
{
mTempOutputFileList->append( new QTemporaryFile() );
Expand Down Expand Up @@ -519,7 +519,7 @@ void eVisDatabaseConnectionGui::on_pbtnRunQuery_clicked()
}
}
outputStream << endl;
myResults->next();
( void )myResults->next();
}
mTempOutputFileList->last()->close();
mDatabaseLayerFieldSelector->setFieldList( &fieldList );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -2486,7 +2486,7 @@ void QgsGdalProvider::initBaseDataset()
}
else
{
GDALGetGeoTransform( mGdalDataset, mGeoTransform );
hasGeoTransform = GDALGetGeoTransform( mGdalDataset, mGeoTransform );
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteconnection.cpp
Expand Up @@ -761,7 +761,7 @@ QgsSqliteHandle* QgsSqliteHandle::openDb( const QString & dbPath, bool shared )
return NULL;
}
// activating Foreign Key constraints
sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, NULL );
( void )sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, NULL );

QgsDebugMsg( "Connection to the database was successful" );

Expand Down
8 changes: 4 additions & 4 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -3709,7 +3709,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
if ( toCommit )
{
// ROLLBACK after some previous error
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
}
}

Expand Down Expand Up @@ -3788,7 +3788,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds &id )
if ( toCommit )
{
// ROLLBACK after some previous error
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
}

return false;
Expand Down Expand Up @@ -3854,7 +3854,7 @@ bool QgsSpatiaLiteProvider::addAttributes( const QList<QgsField> &attributes )
if ( toCommit )
{
// ROLLBACK after some previous error
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
}

return false;
Expand Down Expand Up @@ -3960,7 +3960,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
if ( toCommit )
{
// ROLLBACK after some previous error
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
}

return false;
Expand Down

0 comments on commit 0080f9e

Please sign in to comment.