Skip to content

Commit 349a618

Browse files
committedMay 14, 2016
qgsgml & WFS provider: fix Coverity warnings introduced in recent WFS works
1 parent abd182c commit 349a618

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed
 

‎src/core/qgsgml.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
473473
}
474474
}
475475

476-
const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
476+
const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
477477
bool isGeom = false;
478478
if ( isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )
479479
{
@@ -776,7 +776,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char* el )
776776
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
777777
ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() );
778778

779-
const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
779+
const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
780780

781781
if ( theParseMode == coordinate && isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )
782782
{

‎src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,13 @@ void QgsWFSFeatureIterator::featureReceivedSynchronous( QVector<QgsWFSFeatureGml
856856
mWriterFilename = QDir( QgsWFSUtils::acquireCacheDirectory() ).filePath( QString( "iterator_%1_%2.bin" ).arg( thisStr ).arg( mCounter ) );
857857
QgsDebugMsg( QString( "Transfering feature iterator cache to %1" ).arg( mWriterFilename ) );
858858
mWriterFile = new QFile( mWriterFilename );
859-
mWriterFile->open( QIODevice::WriteOnly );
859+
if ( !mWriterFile->open( QIODevice::WriteOnly ) )
860+
{
861+
QgsDebugMsg( QString( "Cannot open %1 for writing" ).arg( mWriterFilename ) );
862+
delete mWriterFile;
863+
mWriterFile = nullptr;
864+
return;
865+
}
860866
mWriterFile->write( mWriterByteArray );
861867
mWriterByteArray.clear();
862868
mWriterStream->setDevice( mWriterFile );
@@ -975,7 +981,13 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature& f )
975981
else if ( !mReaderFilename.isEmpty() )
976982
{
977983
mReaderFile = new QFile( mReaderFilename );
978-
mReaderFile->open( QIODevice::ReadOnly );
984+
if ( !mReaderFile->open( QIODevice::ReadOnly ) )
985+
{
986+
QgsDebugMsg( QString( "Cannot open %1" ).arg( mReaderFilename ) );
987+
delete mReaderFile;
988+
mReaderFile = nullptr;
989+
return false;
990+
}
979991
mReaderStream = new QDataStream( mReaderFile );
980992
}
981993
}

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,12 @@ bool QgsWFSProvider::processSQL( const QString& sqlString, QString& errorMsg )
290290
return false;
291291
}
292292
const QgsSQLStatement::NodeSelect* select = dynamic_cast<const QgsSQLStatement::NodeSelect*>( sql.rootNode() );
293-
Q_ASSERT( select );
293+
if ( !select )
294+
{
295+
// Makes Coverity happy, but cannot happen in practice
296+
QgsDebugMsg( "should not happen" );
297+
return false;
298+
}
294299
mShared->mDistinctSelect = select->distinct();
295300

296301
QMap< QString, QString > mapTypenameAliasToTypename;

‎src/providers/wfs/qgswfsshareddata.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ bool QgsWFSSharedData::computeFilter( QString& errorMsg )
111111
QgsSQLStatement sql( mURI.sql() );
112112

113113
const QgsSQLStatement::NodeSelect* select = dynamic_cast<const QgsSQLStatement::NodeSelect*>( sql.rootNode() );
114-
Q_ASSERT( select );
114+
if ( !select )
115+
{
116+
// Makes Coverity happy, but cannot happen in practice
117+
QgsDebugMsg( "should not happen" );
118+
return false;
119+
}
115120
QList<QgsSQLStatement::NodeColumnSorted*> orderBy = select->orderBy();
116121
Q_FOREACH ( QgsSQLStatement::NodeColumnSorted* columnSorted, orderBy )
117122
{

‎src/providers/wfs/qgswfssourceselect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class QgsWFSValidatorCallback: public QObject, public QgsSQLComposerDialog::SQLV
407407
{
408408
public:
409409
QgsWFSValidatorCallback( QObject* parent,
410-
QgsWFSDataSourceURI uri, const QString& allSql,
410+
const QgsWFSDataSourceURI& uri, const QString& allSql,
411411
const QgsWFSCapabilities::Capabilities& caps );
412412
bool isValid( const QString& sql, QString& errorReason ) override;
413413
private:
@@ -417,7 +417,7 @@ class QgsWFSValidatorCallback: public QObject, public QgsSQLComposerDialog::SQLV
417417
};
418418

419419
QgsWFSValidatorCallback::QgsWFSValidatorCallback( QObject* parent,
420-
QgsWFSDataSourceURI uri,
420+
const QgsWFSDataSourceURI& uri,
421421
const QString& allSql,
422422
const QgsWFSCapabilities::Capabilities& caps )
423423
: QObject( parent )
@@ -449,7 +449,7 @@ class QgsWFSTableSelectedCallback: public QObject, public QgsSQLComposerDialog::
449449
{
450450
public:
451451
QgsWFSTableSelectedCallback( QgsSQLComposerDialog* dialog,
452-
QgsWFSDataSourceURI uri,
452+
const QgsWFSDataSourceURI& uri,
453453
const QgsWFSCapabilities::Capabilities& caps );
454454
void tableSelected( const QString& name ) override;
455455

@@ -460,7 +460,7 @@ class QgsWFSTableSelectedCallback: public QObject, public QgsSQLComposerDialog::
460460
};
461461

462462
QgsWFSTableSelectedCallback::QgsWFSTableSelectedCallback( QgsSQLComposerDialog* dialog,
463-
QgsWFSDataSourceURI uri,
463+
const QgsWFSDataSourceURI& uri,
464464
const QgsWFSCapabilities::Capabilities& caps )
465465
: QObject( dialog )
466466
, mDialog( dialog )

‎src/providers/wfs/qgswfstransactionrequest.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ bool QgsWFSTransactionRequest::send( const QDomDocument& doc, QDomDocument& serv
2929

3030
if ( sendPOST( url, "text/xml", doc.toByteArray( -1 ) ) )
3131
{
32-
serverResponse.setContent( mResponse, true );
32+
QString errorMsg;
33+
if ( !serverResponse.setContent( mResponse, true, &errorMsg ) )
34+
{
35+
QgsDebugMsg( mResponse );
36+
QgsDebugMsg( errorMsg );
37+
return false;
38+
}
3339
return true;
3440
}
3541
return false;

0 commit comments

Comments
 (0)
Please sign in to comment.