Skip to content

Commit 0080f9e

Browse files
committed
Coverity fixes - unchecked return value
1 parent 8c16daf commit 0080f9e

10 files changed

+31
-38
lines changed

src/analysis/raster/qgsrastercalculator.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
160160
QgsRasterMatrix resultMatrix;
161161

162162
//read / write line by line
163+
bool encounteredError = false;
163164
for ( int i = 0; i < mNumOutputRows; ++i )
164165
{
165166
if ( p )
@@ -178,7 +179,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
178179
{
179180
double sourceTransformation[6];
180181
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
181-
GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation );
182+
if ( !GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation ) )
183+
{
184+
encounteredError = true;
185+
break;
186+
}
182187
//the function readRasterPart calls GDALRasterIO (and ev. does some conversion if raster transformations are not the same)
183188
readRasterPart( targetGeoTransform, 0, i, mNumOutputColumns, 1, sourceTransformation, sourceRasterBand, bufferIt.value()->data() );
184189
}
@@ -244,11 +249,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
244249
GDALClose( *datasetIt );
245250
}
246251

247-
if ( p && p->wasCanceled() )
252+
if (( p && p->wasCanceled() ) || encounteredError )
248253
{
249254
//delete the dataset without closing (because it is faster)
250255
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
251-
return 3;
256+
return encounteredError ? 1 : 3;
252257
}
253258
GDALClose( outputDataset );
254259
CPLFree( resultScanLine );

src/app/qgscustomprojectiondialog.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ bool QgsCustomProjectionDialog::deleteCRS( QString id )
161161
Q_ASSERT( myResult == SQLITE_OK );
162162
}
163163
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
164-
sqlite3_step( myPreparedStatement );
165164
// XXX Need to free memory from the error msg if one is set
166-
if ( myResult != SQLITE_OK )
165+
if ( myResult != SQLITE_OK || sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
167166
{
168167
QgsDebugMsg( QString( "failed to remove CRS from database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
169168
}
@@ -218,11 +217,11 @@ void QgsCustomProjectionDialog::insertProjection( QString myProjectionAcronym )
218217
+ ")"
219218
;
220219
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.length(), &myPreparedStatement, &myTail );
221-
sqlite3_step( myPreparedStatement );
222-
if ( myResult != SQLITE_OK )
220+
if ( myResult != SQLITE_OK || sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
223221
{
224222
QgsDebugMsg( QString( "Update or insert failed in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
225223
}
224+
226225
sqlite3_finalize( myPreparedStatement );
227226
}
228227

@@ -279,9 +278,8 @@ bool QgsCustomProjectionDialog::saveCRS( QgsCoordinateReferenceSystem myCRS, QSt
279278
Q_ASSERT( myResult == SQLITE_OK );
280279
}
281280
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
282-
sqlite3_step( myPreparedStatement );
283281
// XXX Need to free memory from the error msg if one is set
284-
if ( myResult != SQLITE_OK )
282+
if ( myResult != SQLITE_OK || sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
285283
{
286284
QgsDebugMsg( QString( "failed to write to database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
287285
}

src/core/qgscoordinatereferencesystem.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -1512,13 +1512,12 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )
15121512
}
15131513
QgsDebugMsg( QString( "Update or insert sql \n%1" ).arg( mySql ) );
15141514
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1515-
sqlite3_step( myPreparedStatement );
1516-
1517-
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );
15181515

15191516
qint64 return_id;
1520-
if ( myResult == SQLITE_OK )
1517+
if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
15211518
{
1519+
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );
1520+
15221521
return_id = sqlite3_last_insert_rowid( myDatabase );
15231522
setInternalId( return_id );
15241523

@@ -1716,14 +1715,13 @@ int QgsCoordinateReferenceSystem::syncDb()
17161715
{
17171716
qCritical( "Could not begin transaction: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
17181717
return -1;
1719-
17201718
}
17211719

17221720
// fix up database, if not done already //
17231721
if ( sqlite3_exec( database, "alter table tbl_srs add noupdate boolean", 0, 0, 0 ) == SQLITE_OK )
1724-
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 );
1722+
( 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 );
17251723

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

17281726
OGRSpatialReferenceH crs = OSRNewSpatialReference( NULL );
17291727
const char *tail;

src/core/symbology-ng/qgsstylev2.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ int QgsStyleV2::addGroup( QString groupName, int parentid )
620620
sqlite3_stmt *ppStmt;
621621
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
622622
if ( nErr == SQLITE_OK )
623-
sqlite3_step( ppStmt );
623+
( void )sqlite3_step( ppStmt );
624624

625625
sqlite3_finalize( ppStmt );
626626

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

642642
return ( int )sqlite3_last_insert_rowid( mCurrentDB );

src/gui/qgsprojectionselector.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -581,22 +581,14 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
581581
showDBMissingWarning( mSrsDatabaseFileName );
582582
return;
583583
}
584-
// prepare the sql statement
584+
585585
const char *tail;
586586
sqlite3_stmt *stmt;
587-
// get total count of records in the projection table
588-
QString sql = "select count(*) from tbl_srs";
589-
590-
rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
591-
Q_ASSERT( rc == SQLITE_OK );
592-
sqlite3_step( stmt );
593-
sqlite3_finalize( stmt );
594-
595587
// Set up the query to retrieve the projection information needed to populate the list
596588
//note I am giving the full field names for clarity here and in case someone
597589
//changes the underlying view TS
598-
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" )
599-
.arg( sqlFilter );
590+
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" )
591+
.arg( sqlFilter );
600592

601593
rc = sqlite3_prepare( database, sql.toUtf8(), sql.toUtf8().length(), &stmt, &tail );
602594
// XXX Need to free memory from the error msg if one is set

src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLay
7171

7272
void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
7373
{
74-
if ( layer && layer->layerType() != "EllipseMarker" )
74+
if ( !layer || layer->layerType() != "EllipseMarker" )
7575
{
7676
return;
7777
}

src/plugins/evis/databaseconnection/evisdatabaseconnectiongui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ void eVisDatabaseConnectionGui::on_pbtnRunQuery_clicked()
478478
else if ( myResults->isSelect() )
479479
{
480480
//if valid and a select query, save results into temporary file and load as layer
481-
myResults->next();
481+
( void )myResults->next();
482482
if ( myResults->isValid() )
483483
{
484484
mTempOutputFileList->append( new QTemporaryFile() );
@@ -519,7 +519,7 @@ void eVisDatabaseConnectionGui::on_pbtnRunQuery_clicked()
519519
}
520520
}
521521
outputStream << endl;
522-
myResults->next();
522+
( void )myResults->next();
523523
}
524524
mTempOutputFileList->last()->close();
525525
mDatabaseLayerFieldSelector->setFieldList( &fieldList );

src/providers/gdal/qgsgdalprovider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ void QgsGdalProvider::initBaseDataset()
24862486
}
24872487
else
24882488
{
2489-
GDALGetGeoTransform( mGdalDataset, mGeoTransform );
2489+
hasGeoTransform = GDALGetGeoTransform( mGdalDataset, mGeoTransform );
24902490
}
24912491
}
24922492
else

src/providers/spatialite/qgsspatialiteconnection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ QgsSqliteHandle* QgsSqliteHandle::openDb( const QString & dbPath, bool shared )
761761
return NULL;
762762
}
763763
// activating Foreign Key constraints
764-
sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, NULL );
764+
( void )sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, NULL );
765765

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

src/providers/spatialite/qgsspatialiteprovider.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
37093709
if ( toCommit )
37103710
{
37113711
// ROLLBACK after some previous error
3712-
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
3712+
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
37133713
}
37143714
}
37153715

@@ -3788,7 +3788,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds &id )
37883788
if ( toCommit )
37893789
{
37903790
// ROLLBACK after some previous error
3791-
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
3791+
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
37923792
}
37933793

37943794
return false;
@@ -3854,7 +3854,7 @@ bool QgsSpatiaLiteProvider::addAttributes( const QList<QgsField> &attributes )
38543854
if ( toCommit )
38553855
{
38563856
// ROLLBACK after some previous error
3857-
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
3857+
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
38583858
}
38593859

38603860
return false;
@@ -3960,7 +3960,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
39603960
if ( toCommit )
39613961
{
39623962
// ROLLBACK after some previous error
3963-
sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
3963+
( void )sqlite3_exec( sqliteHandle, "ROLLBACK", NULL, NULL, NULL );
39643964
}
39653965

39663966
return false;

0 commit comments

Comments
 (0)