Skip to content

Commit

Permalink
qgsgml & WFS provider: fix Coverity warnings introduced in recent WFS…
Browse files Browse the repository at this point in the history
… works
  • Loading branch information
rouault committed May 14, 2016
1 parent abd182c commit 349a618
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsgml.cpp
Expand Up @@ -473,7 +473,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
}
}

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

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

if ( theParseMode == coordinate && isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )
{
Expand Down
16 changes: 14 additions & 2 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -856,7 +856,13 @@ void QgsWFSFeatureIterator::featureReceivedSynchronous( QVector<QgsWFSFeatureGml
mWriterFilename = QDir( QgsWFSUtils::acquireCacheDirectory() ).filePath( QString( "iterator_%1_%2.bin" ).arg( thisStr ).arg( mCounter ) );
QgsDebugMsg( QString( "Transfering feature iterator cache to %1" ).arg( mWriterFilename ) );
mWriterFile = new QFile( mWriterFilename );
mWriterFile->open( QIODevice::WriteOnly );
if ( !mWriterFile->open( QIODevice::WriteOnly ) )
{
QgsDebugMsg( QString( "Cannot open %1 for writing" ).arg( mWriterFilename ) );
delete mWriterFile;
mWriterFile = nullptr;
return;
}
mWriterFile->write( mWriterByteArray );
mWriterByteArray.clear();
mWriterStream->setDevice( mWriterFile );
Expand Down Expand Up @@ -975,7 +981,13 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature& f )
else if ( !mReaderFilename.isEmpty() )
{
mReaderFile = new QFile( mReaderFilename );
mReaderFile->open( QIODevice::ReadOnly );
if ( !mReaderFile->open( QIODevice::ReadOnly ) )
{
QgsDebugMsg( QString( "Cannot open %1" ).arg( mReaderFilename ) );
delete mReaderFile;
mReaderFile = nullptr;
return false;
}
mReaderStream = new QDataStream( mReaderFile );
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -290,7 +290,12 @@ bool QgsWFSProvider::processSQL( const QString& sqlString, QString& errorMsg )
return false;
}
const QgsSQLStatement::NodeSelect* select = dynamic_cast<const QgsSQLStatement::NodeSelect*>( sql.rootNode() );
Q_ASSERT( select );
if ( !select )
{
// Makes Coverity happy, but cannot happen in practice
QgsDebugMsg( "should not happen" );
return false;
}
mShared->mDistinctSelect = select->distinct();

QMap< QString, QString > mapTypenameAliasToTypename;
Expand Down
7 changes: 6 additions & 1 deletion src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -111,7 +111,12 @@ bool QgsWFSSharedData::computeFilter( QString& errorMsg )
QgsSQLStatement sql( mURI.sql() );

const QgsSQLStatement::NodeSelect* select = dynamic_cast<const QgsSQLStatement::NodeSelect*>( sql.rootNode() );
Q_ASSERT( select );
if ( !select )
{
// Makes Coverity happy, but cannot happen in practice
QgsDebugMsg( "should not happen" );
return false;
}
QList<QgsSQLStatement::NodeColumnSorted*> orderBy = select->orderBy();
Q_FOREACH ( QgsSQLStatement::NodeColumnSorted* columnSorted, orderBy )
{
Expand Down
8 changes: 4 additions & 4 deletions src/providers/wfs/qgswfssourceselect.cpp
Expand Up @@ -407,7 +407,7 @@ class QgsWFSValidatorCallback: public QObject, public QgsSQLComposerDialog::SQLV
{
public:
QgsWFSValidatorCallback( QObject* parent,
QgsWFSDataSourceURI uri, const QString& allSql,
const QgsWFSDataSourceURI& uri, const QString& allSql,
const QgsWFSCapabilities::Capabilities& caps );
bool isValid( const QString& sql, QString& errorReason ) override;
private:
Expand All @@ -417,7 +417,7 @@ class QgsWFSValidatorCallback: public QObject, public QgsSQLComposerDialog::SQLV
};

QgsWFSValidatorCallback::QgsWFSValidatorCallback( QObject* parent,
QgsWFSDataSourceURI uri,
const QgsWFSDataSourceURI& uri,
const QString& allSql,
const QgsWFSCapabilities::Capabilities& caps )
: QObject( parent )
Expand Down Expand Up @@ -449,7 +449,7 @@ class QgsWFSTableSelectedCallback: public QObject, public QgsSQLComposerDialog::
{
public:
QgsWFSTableSelectedCallback( QgsSQLComposerDialog* dialog,
QgsWFSDataSourceURI uri,
const QgsWFSDataSourceURI& uri,
const QgsWFSCapabilities::Capabilities& caps );
void tableSelected( const QString& name ) override;

Expand All @@ -460,7 +460,7 @@ class QgsWFSTableSelectedCallback: public QObject, public QgsSQLComposerDialog::
};

QgsWFSTableSelectedCallback::QgsWFSTableSelectedCallback( QgsSQLComposerDialog* dialog,
QgsWFSDataSourceURI uri,
const QgsWFSDataSourceURI& uri,
const QgsWFSCapabilities::Capabilities& caps )
: QObject( dialog )
, mDialog( dialog )
Expand Down
8 changes: 7 additions & 1 deletion src/providers/wfs/qgswfstransactionrequest.cpp
Expand Up @@ -29,7 +29,13 @@ bool QgsWFSTransactionRequest::send( const QDomDocument& doc, QDomDocument& serv

if ( sendPOST( url, "text/xml", doc.toByteArray( -1 ) ) )
{
serverResponse.setContent( mResponse, true );
QString errorMsg;
if ( !serverResponse.setContent( mResponse, true, &errorMsg ) )
{
QgsDebugMsg( mResponse );
QgsDebugMsg( errorMsg );
return false;
}
return true;
}
return false;
Expand Down

0 comments on commit 349a618

Please sign in to comment.