Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor Coverity fixups, clang warnings, 0->nullptr conversions
  • Loading branch information
nyalldawson committed Jan 3, 2016
1 parent 2eb95f0 commit fe9a098
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -374,6 +374,7 @@ QgsDxfExport& QgsDxfExport::operator=( const QgsDxfExport & dxfExport )
mSymbologyScaleDenominator = dxfExport.mSymbologyScaleDenominator;
mSymbologyExport = dxfExport.mSymbologyExport;
mMapUnits = dxfExport.mMapUnits;
mLayerTitleAsName = dxfExport.mLayerTitleAsName;
mSymbolLayerCounter = 0; // internal counter
mNextHandleId = 0;
mBlockCounter = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsexpression.cpp
Expand Up @@ -3116,7 +3116,7 @@ void QgsExpression::detach()

if ( d->ref > 1 )
{
d->ref.deref();
( void )d->ref.deref();

d = new QgsExpressionPrivate( *d );
}
Expand Down
32 changes: 20 additions & 12 deletions src/providers/virtual/qgsvirtuallayerblob.cpp
Expand Up @@ -17,9 +17,17 @@ email : hugo dot mercier at oslandia dot com

#include "qgsvirtuallayerblob.h"
#include <string.h>

SpatialiteBlobHeader::SpatialiteBlobHeader() :
start( 0x00 ), endianness( 0x01 ), end( 0x7C )
#include <limits>

SpatialiteBlobHeader::SpatialiteBlobHeader()
: start( 0x00 )
, endianness( 0x01 )
, srid( -1 )
, mbrMinX( -DBL_MAX )
, mbrMinY( -DBL_MAX )
, mbrMaxX( DBL_MAX )
, mbrMaxY( DBL_MAX )
, end( 0x7C )
{}

void SpatialiteBlobHeader::readFrom( const char* p )
Expand Down Expand Up @@ -130,7 +138,7 @@ void copySpatialiteSingleWkbToQgsGeometry( QgsWKBTypes::Type type, const char* i
break;
case QgsWKBTypes::LineString:
{
uint32_t n_points = *( uint32_t* )iwkb;
uint32_t n_points = *( reinterpret_cast<const uint32_t*>( iwkb ) );
memcpy( owkb, iwkb, 4 );
iwkb += 4;
owkb += 4;
Expand All @@ -145,14 +153,14 @@ void copySpatialiteSingleWkbToQgsGeometry( QgsWKBTypes::Type type, const char* i
}
case QgsWKBTypes::Polygon:
{
uint32_t n_rings = *( uint32_t* )iwkb;
uint32_t n_rings = *( reinterpret_cast<const uint32_t*>( iwkb ) );
memcpy( owkb, iwkb, 4 );
iwkb += 4;
owkb += 4;
osize = 4;
for ( uint32_t i = 0; i < n_rings; i++ )
{
uint32_t n_points = *( uint32_t* )iwkb;
uint32_t n_points = *( reinterpret_cast<const uint32_t*>( iwkb ) );
memcpy( owkb, iwkb, 4 );
iwkb += 4;
owkb += 4;
Expand Down Expand Up @@ -185,12 +193,12 @@ void copySpatialiteCollectionWkbToQgsGeometry( const char* iwkb, char* owkb, uin
// replace 0x69 by the endianness
owkb[0] = endianness;

QgsWKBTypes::Type type = static_cast<QgsWKBTypes::Type>( *( uint32_t* )( iwkb + 1 ) );
QgsWKBTypes::Type type = static_cast<QgsWKBTypes::Type>( *( reinterpret_cast<const uint32_t*>( iwkb + 1 ) ) );

if ( QgsWKBTypes::isMultiType( type ) )
{
// multi type
uint32_t n_elements = *( uint32_t* )( iwkb + 5 );
uint32_t n_elements = *( reinterpret_cast<const uint32_t* >( iwkb + 5 ) );
memcpy( owkb + 5, iwkb + 5, 4 );
uint32_t p = 0;
for ( uint32_t i = 0; i < n_elements; i++ )
Expand All @@ -212,14 +220,14 @@ void copySpatialiteCollectionWkbToQgsGeometry( const char* iwkb, char* owkb, uin
QgsGeometry spatialiteBlobToQgsGeometry( const char* blob, size_t size )
{
const int header_size = SpatialiteBlobHeader::length;
const int wkb_size = ( const int )( size - header_size );
const int wkb_size = static_cast< const int >( size - header_size );
char* wkb = new char[wkb_size];

uint32_t osize = 0;
copySpatialiteCollectionWkbToQgsGeometry( blob + header_size - 1, wkb, osize, /*endianness*/blob[1] );

QgsGeometry geom;
geom.fromWkb(( unsigned char* )wkb, wkb_size );
geom.fromWkb( reinterpret_cast< unsigned char* >( wkb ), wkb_size );
return geom;
}

Expand All @@ -230,8 +238,8 @@ QPair<QgsWKBTypes::Type, long> spatialiteBlobGeometryType( const char* blob, siz
return qMakePair( QgsWKBTypes::NoGeometry, long( 0 ) );
}

uint32_t srid = *( uint32_t* )( blob + 2 );
uint32_t type = *( uint32_t* )( blob + SpatialiteBlobHeader::length );
uint32_t srid = *( reinterpret_cast< const uint32_t* >( blob + 2 ) );
uint32_t type = *( reinterpret_cast< const uint32_t* >( blob + SpatialiteBlobHeader::length ) );

return qMakePair( static_cast<QgsWKBTypes::Type>( type ), long( srid ) );
}
3 changes: 0 additions & 3 deletions src/providers/virtual/qgsvirtuallayerfeatureiterator.h
Expand Up @@ -62,9 +62,6 @@ class QgsVirtualLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSour

QString mSqlQuery;

// Index of the id column, -1 if none
int mUidColumn;

QgsAttributeList mAttributes;
};

Expand Down
9 changes: 5 additions & 4 deletions src/providers/virtual/qgsvirtuallayerprovider.cpp
Expand Up @@ -49,9 +49,10 @@ static QString quotedColumn( QString name )


QgsVirtualLayerProvider::QgsVirtualLayerProvider( QString const &uri )
: QgsVectorDataProvider( uri ),
mValid( true ),
mCachedStatistics( false )
: QgsVectorDataProvider( uri )
, mValid( true )
, mCachedStatistics( false )
, mFeatureCount( 0 )
{
mError.clear();

Expand Down Expand Up @@ -103,7 +104,7 @@ bool QgsVirtualLayerProvider::loadSourceLayers()
if ( layer.isReferenced() )
{
QgsMapLayer *l = QgsMapLayerRegistry::instance()->mapLayer( layer.reference() );
if ( l == 0 )
if ( !l )
{
PROVIDER_ERROR( QString( "Cannot find layer %1" ).arg( layer.reference() ) );
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/virtual/qgsvirtuallayerqueryparser.cpp
Expand Up @@ -22,7 +22,7 @@ namespace QgsVirtualLayerQueryParser

while ( true )
{
char *errMsg = 0;
char *errMsg = nullptr;
int r = sqlite3_exec( db.get(), query.toLocal8Bit().constData(), NULL, NULL, &errMsg );
QString err = errMsg;
if ( r && err.startsWith( noSuchError ) )
Expand All @@ -32,7 +32,7 @@ namespace QgsVirtualLayerQueryParser

// create a dummy table to skip this error
QString createStr = QString( "CREATE TABLE \"%1\" (id int)" ).arg( tableName.replace( "\"", "\"\"" ) );
sqlite3_exec( db.get(), createStr.toLocal8Bit().constData(), NULL, NULL, NULL );
( void )sqlite3_exec( db.get(), createStr.toLocal8Bit().constData(), NULL, NULL, NULL );
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions src/providers/virtual/qgsvirtuallayersqlitehelper.cpp
Expand Up @@ -26,7 +26,7 @@ QgsScopedSqlite::QgsScopedSqlite( const QString& path, bool withExtension )
{
// register a statically-linked function as extension
// for all future database connection
sqlite3_auto_extension(( void( * )() )qgsvlayer_module_init );
sqlite3_auto_extension( reinterpret_cast < void( * )() > ( qgsvlayer_module_init ) );
}
int r;
r = sqlite3_open( path.toLocal8Bit().constData(), &db_ );
Expand All @@ -47,7 +47,7 @@ QgsScopedSqlite::QgsScopedSqlite( const QString& path, bool withExtension )
QgsScopedSqlite::QgsScopedSqlite( QgsScopedSqlite& other )
{
db_ = other.db_;
other.db_ = 0;
other.db_ = nullptr;
}

QgsScopedSqlite& QgsScopedSqlite::operator=( QgsScopedSqlite & other )
Expand All @@ -66,7 +66,7 @@ sqlite3* QgsScopedSqlite::get() const { return db_; }
sqlite3* QgsScopedSqlite::release()
{
sqlite3* pp = db_;
db_ = 0;
db_ = nullptr;
return pp;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ namespace Sqlite

void Query::exec( sqlite3* db, const QString& sql )
{
char *errMsg = 0;
char *errMsg = nullptr;
int r = sqlite3_exec( db, sql.toLocal8Bit().constData(), NULL, NULL, &errMsg );
if ( r )
{
Expand Down Expand Up @@ -172,14 +172,14 @@ namespace Sqlite
QString Query::columnText( int i ) const
{
int size = sqlite3_column_bytes( stmt_, i );
const char* str = ( const char* )sqlite3_column_text( stmt_, i );
const char* str = reinterpret_cast< const char* >( sqlite3_column_text( stmt_, i ) );
return QString::fromUtf8( str, size );
}

QByteArray Query::columnBlob( int i ) const
{
int size = sqlite3_column_bytes( stmt_, i );
const char* data = ( const char* )sqlite3_column_blob( stmt_, i );
const char* data = reinterpret_cast< const char* >( sqlite3_column_blob( stmt_, i ) );
// data is not copied. QByteArray is just here a augmented pointer
return QByteArray::fromRawData( data, size );
}
Expand Down
56 changes: 36 additions & 20 deletions src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
Expand Up @@ -76,7 +76,7 @@ void initVirtualLayerMetadata( sqlite3* db )

void deleteGeometryBlob( void * p )
{
delete[]( unsigned char* )p;
delete[]( reinterpret_cast< unsigned char* >( p ) );
}

//-----------------------------------------------------------------------
Expand All @@ -96,21 +96,37 @@ struct VTable
char *zErrMsg; /* Error message from sqlite3_mprintf() */

VTable( sqlite3* db, QgsVectorLayer* layer )
: zErrMsg( 0 ), mSql( db ), mProvider( 0 ), mLayer( layer ), mSlotToFunction( invalidateTable, this ), mName( layer->name() ), mPkColumn( -1 ), mValid( true )
: pModule( nullptr )
, nRef( 0 )
, zErrMsg( nullptr )
, mSql( db )
, mProvider( nullptr )
, mLayer( layer )
, mSlotToFunction( invalidateTable, this )
, mName( layer->name() )
, mPkColumn( -1 )
, mValid( true )
{
if ( mLayer )
{
QObject::connect( layer, SIGNAL( layerDeleted() ), &mSlotToFunction, SLOT( onSignal() ) );
init_();
}

init_();
}

VTable( sqlite3* db, const QString& provider, const QString& source, const QString& name, const QString& encoding )
: zErrMsg( 0 ), mSql( db ), mLayer( 0 ), mName( name ), mEncoding( encoding ), mPkColumn( -1 ), mValid( true )
: pModule( nullptr )
, nRef( 0 )
, zErrMsg( nullptr )
, mSql( db )
, mLayer( nullptr )
, mName( name )
, mEncoding( encoding )
, mPkColumn( -1 )
, mValid( true )
{
mProvider = static_cast<QgsVectorDataProvider*>( QgsProviderRegistry::instance()->provider( provider, source ) );
if ( mProvider == 0 || !mProvider->isValid() )
if ( !mProvider || !mProvider->isValid() )
{
throw std::runtime_error( "Invalid provider" );
}
Expand Down Expand Up @@ -241,7 +257,7 @@ struct VTableCursor

VTableCursor( VTable *vtab ) : mVtab( vtab ), mEof( true ) {}

void filter( QgsFeatureRequest request )
void filter( const QgsFeatureRequest& request )
{
if ( !mVtab->valid() )
{
Expand Down Expand Up @@ -279,7 +295,7 @@ struct VTableCursor
QPair<char*, int> currentGeometry() const
{
int blob_len = 0;
char* blob = 0;
char* blob = nullptr;
const QgsGeometry* g = mCurrentFeature.constGeometry();
if ( g && ! g->isEmpty() )
{
Expand All @@ -292,7 +308,7 @@ struct VTableCursor
void getGeometryType( const QgsVectorDataProvider* provider, QString& geometryTypeStr, int& geometryDim, int& geometryWkbType, long& srid )
{
srid = const_cast<QgsVectorDataProvider*>( provider )->crs().postgisSrid();
QgsWKBTypes::Type t = static_cast<QgsWKBTypes::Type>( provider->geometryType() );
QgsWKBTypes::Type t = QGis::fromOldWkbType( provider->geometryType() );
geometryTypeStr = QgsWKBTypes::displayString( t );
geometryDim = QgsWKBTypes::coordDimensions( t );
if (( t != QgsWKBTypes::NoGeometry ) && ( t != QgsWKBTypes::Unknown ) )
Expand All @@ -306,8 +322,8 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
Q_UNUSED( aux );
Q_UNUSED( is_created );

#define RETURN_CSTR_ERROR(err) if (out_err) {size_t s = strlen(err); *out_err=(char*)sqlite3_malloc( (int) s+1); strncpy(*out_err, err, s);}
#define RETURN_CPPSTR_ERROR(err) if (out_err) {*out_err=(char*)sqlite3_malloc( (int) err.size()+1); strncpy(*out_err, err.c_str(), err.size());}
#define RETURN_CSTR_ERROR(err) if (out_err) {size_t s = strlen(err); *out_err=reinterpret_cast<char*>(sqlite3_malloc( static_cast<int>( s ) +1)); strncpy(*out_err, err, s);}
#define RETURN_CPPSTR_ERROR(err) if (out_err) {*out_err=reinterpret_cast<char*>(sqlite3_malloc( static_cast<int>( err.size() )+1)); strncpy(*out_err, err.c_str(), err.size());}

if ( argc < 4 )
{
Expand All @@ -330,7 +346,7 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
layerid = layerid.mid( 1, layerid.size() - 2 );
}
QgsMapLayer *l = QgsMapLayerRegistry::instance()->mapLayer( layerid );
if ( l == 0 || l->type() != QgsMapLayer::VectorLayer )
if ( !l || l->type() != QgsMapLayer::VectorLayer )
{
if ( out_err )
{
Expand Down Expand Up @@ -386,7 +402,7 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
return r;
}

*out_vtab = ( sqlite3_vtab* )new_vtab.take();
*out_vtab = reinterpret_cast< sqlite3_vtab* >( new_vtab.take() );
return SQLITE_OK;
#undef RETURN_CSTR_ERROR
#undef RETURN_CPPSTR_ERROR
Expand Down Expand Up @@ -414,7 +430,7 @@ int vtable_create( sqlite3* sql, void* aux, int argc, const char* const* argv, s
{
if ( out_err )
{
*out_err = ( char* )sqlite3_malloc(( int ) strlen( e.what() ) + 1 );
*out_err = reinterpret_cast< char* >( sqlite3_malloc( static_cast< int >( strlen( e.what() ) ) + 1 ) );
strcpy( *out_err, e.what() );
}
return SQLITE_ERROR;
Expand Down Expand Up @@ -456,7 +472,7 @@ int vtable_rename( sqlite3_vtab *vtab, const char *new_name )

int vtable_bestindex( sqlite3_vtab *pvtab, sqlite3_index_info* index_info )
{
VTable *vtab = ( VTable* )pvtab;
VTable *vtab = reinterpret_cast< VTable* >( pvtab );
for ( int i = 0; i < index_info->nConstraint; i++ )
{
if (( index_info->aConstraint[i].usable ) &&
Expand Down Expand Up @@ -499,8 +515,8 @@ int vtable_bestindex( sqlite3_vtab *pvtab, sqlite3_index_info* index_info )

int vtable_open( sqlite3_vtab *vtab, sqlite3_vtab_cursor **out_cursor )
{
VTableCursor *ncursor = new VTableCursor(( VTable* )vtab );
*out_cursor = ( sqlite3_vtab_cursor* )ncursor;
VTableCursor *ncursor = new VTableCursor( reinterpret_cast< VTable* >( vtab ) );
*out_cursor = reinterpret_cast< sqlite3_vtab_cursor* >( ncursor );
return SQLITE_OK;
}

Expand All @@ -527,7 +543,7 @@ int vtable_filter( sqlite3_vtab_cursor * cursor, int idxNum, const char *idxStr,
else if ( idxNum == 2 )
{
// rtree filter
const char* blob = ( const char* )sqlite3_value_blob( argv[0] );
const char* blob = reinterpret_cast< const char* >( sqlite3_value_blob( argv[0] ) );
int bytes = sqlite3_value_bytes( argv[0] );
QgsRectangle r( spatialiteBlobBbox( blob, bytes ) );
request.setFilterRect( r );
Expand Down Expand Up @@ -623,7 +639,7 @@ int vtable_findfunction( sqlite3_vtab *pVtab,

sqlite3_module module;

static QCoreApplication* core_app = 0;
static QCoreApplication* core_app = nullptr;

static int module_argc = 1;
static char module_name[] = "qgsvlayer_module";
Expand All @@ -647,7 +663,7 @@ int qgsvlayer_module_init( sqlite3 *db, char **pzErrMsg, void * unused /*const s
int rc = SQLITE_OK;

// check if qgis providers are loaded
if ( QCoreApplication::instance() == 0 )
if ( !QCoreApplication::instance() )
{
// if run standalone
core_app = new QCoreApplication( module_argc, module_argv );
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsserverprojectparser.cpp
Expand Up @@ -1234,7 +1234,7 @@ QList<QDomElement> QgsServerProjectParser::setLegendGroupElementsWithLayerTree(
QgsLayerTreeNode* layerTreeNode = layerTreeGroupChildren.at( j );
if ( layerTreeNode->nodeType() != QgsLayerTreeNode::NodeGroup )
continue;
QgsLayerTreeGroup* layerTreeGroup = dynamic_cast<QgsLayerTreeGroup *>( layerTreeNode );
QgsLayerTreeGroup* layerTreeGroup = static_cast<QgsLayerTreeGroup *>( layerTreeNode );
if ( layerTreeGroup->name() == legendElement.attribute( "name" ) )
{
g = j;
Expand Down

0 comments on commit fe9a098

Please sign in to comment.