Skip to content

Commit

Permalink
Fix cppcheck shadowVariable warnings in src/core/
Browse files Browse the repository at this point in the history
Found with
~/cppcheck/cppcheck --enable=all --inconclusive  ../src/core --library=$HOME/cppcheck/cfg/qt.cfg -j 8 -DSIP_OUT 2>&1 | grep shadowVariable

I don't think any bug was found, but better avoid such situations.
  • Loading branch information
rouault authored and nyalldawson committed Jan 30, 2020
1 parent 385d3ec commit 1b88cc3
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 107 deletions.
12 changes: 7 additions & 5 deletions src/core/annotations/qgsannotation.cpp
Expand Up @@ -493,13 +493,15 @@ void QgsAnnotation::_readXml( const QDomElement &annotationElem, const QgsReadWr
}

//marker symbol
QDomElement symbolElem = annotationElem.firstChildElement( QStringLiteral( "symbol" ) );
if ( !symbolElem.isNull() )
{
QgsMarkerSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context );
if ( symbol )
QDomElement symbolElem = annotationElem.firstChildElement( QStringLiteral( "symbol" ) );
if ( !symbolElem.isNull() )
{
mMarkerSymbol.reset( symbol );
QgsMarkerSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context );
if ( symbol )
{
mMarkerSymbol.reset( symbol );
}
}
}

Expand Down
Expand Up @@ -135,7 +135,8 @@ QVariant QgsRelationReferenceFieldFormatter::createCache( QgsVectorLayer *layer,
QgsMessageLog::logMessage( QObject::tr( "Layer %1, field %2: Cannot find referenced layer" ).arg( layer->name(), fieldName ) );
return QVariant();
}
int referencedFieldIdx = referencedLayer->fields().lookupField( relation.fieldPairs().at( 0 ).second );

const int referencedFieldIdx = referencedLayer->fields().lookupField( relation.fieldPairs().at( 0 ).second );
if ( referencedFieldIdx == -1 )
{
QgsMessageLog::logMessage( QObject::tr( "Layer %1, field %2: Invalid referenced field (%3) configured in relation %4" ).arg( layer->name(), fieldName, relation.fieldPairs().at( 0 ).second, relation.name() ) );
Expand Down Expand Up @@ -163,7 +164,6 @@ QVariant QgsRelationReferenceFieldFormatter::createCache( QgsVectorLayer *layer,

if ( expr.hasEvalError() )
{
int referencedFieldIdx = referencedLayer->fields().lookupField( relation.fieldPairs().at( 0 ).second );
title = feature.attribute( referencedFieldIdx ).toString();
}

Expand Down
6 changes: 2 additions & 4 deletions src/core/gps/qgsqtlocationconnection.cpp
Expand Up @@ -124,9 +124,8 @@ void QgsQtLocationConnection::satellitesInUseUpdated(
mLastGPSInformation.satellitesUsed = QString::number( satellites.count() ).toInt();

mLastGPSInformation.satPrn.clear();
for ( int i = 0; i < satellites.size(); ++i )
for ( const QGeoSatelliteInfo &currentSatellite : satellites )
{
QGeoSatelliteInfo currentSatellite = satellites.at( i );
//add pnr to mLastGPSInformation.satPrn
#if defined(HAVE_QT_MOBILITY_LOCATION )
mLastGPSInformation.satPrn.append( currentSatellite.prnNumber() );
Expand All @@ -135,9 +134,8 @@ void QgsQtLocationConnection::satellitesInUseUpdated(
#endif

//set QgsSatelliteInfo.inuse to true for the satellites in use
for ( int i = 0; i < mLastGPSInformation.satellitesInView.size(); ++i )
for ( QgsSatelliteInfo &satInView : mLastGPSInformation.satellitesInView )
{
QgsSatelliteInfo satInView = mLastGPSInformation.satellitesInView.at( i );
#if defined(HAVE_QT_MOBILITY_LOCATION )
if ( satInView.id == currentSatellite.prnNumber() )
#else // QtPositioning
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmeshlayerinterpolator.cpp
Expand Up @@ -126,12 +126,12 @@ QgsRasterBlock *QgsMeshLayerInterpolator::block( int, const QgsRectangle &extent
p );
else
{
int face = mTriangularMesh.trianglesToNativeFaces()[i];
const int faceIdx = mTriangularMesh.trianglesToNativeFaces()[i];
val = QgsMeshLayerUtils::interpolateFromFacesData(
p1,
p2,
p3,
mDatasetValues[face],
mDatasetValues[faceIdx],
p
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/layer.cpp
Expand Up @@ -470,8 +470,8 @@ void Layer::chopFeaturesAtRepeatDistance()
repeatParts.push_back( newfpart );
}

for ( FeaturePart *part : repeatParts )
part->setTotalRepeats( repeatParts.count() );
for ( FeaturePart *partPtr : repeatParts )
partPtr->setTotalRepeats( repeatParts.count() );
}
else
{
Expand Down
21 changes: 8 additions & 13 deletions src/core/pal/problem.cpp
Expand Up @@ -162,7 +162,6 @@ void ignoreLabel( const LabelPosition *lp, PriorityQueue &list, PalRtree< LabelP
*/
void Problem::init_sol_falp()
{
int i, j;
int label;

mSol.init( mFeatureCount );
Expand All @@ -174,8 +173,8 @@ void Problem::init_sol_falp()

LabelPosition *lp = nullptr;

for ( i = 0; i < static_cast< int >( mFeatureCount ); i++ )
for ( j = 0; j < mFeatNbLp[i]; j++ )
for ( int i = 0; i < static_cast< int >( mFeatureCount ); i++ )
for ( int j = 0; j < mFeatNbLp[i]; j++ )
{
label = mFeatStartId[i] + j;
try
Expand Down Expand Up @@ -207,7 +206,7 @@ void Problem::init_sol_falp()
int probFeatId = lp->getProblemFeatureId();
mSol.activeLabelIds[probFeatId] = label;

for ( i = mFeatStartId[probFeatId]; i < mFeatStartId[probFeatId] + mFeatNbLp[probFeatId]; i++ )
for ( int i = mFeatStartId[probFeatId]; i < mFeatStartId[probFeatId] + mFeatNbLp[probFeatId]; i++ )
{
ignoreLabel( mLabelPositions[ i ].get(), list, mAllCandidatesIndex );
}
Expand Down Expand Up @@ -280,9 +279,6 @@ void Problem::init_sol_falp()

inline Chain *Problem::chain( int seed )
{
int i;
int j;

int lid;

double delta;
Expand Down Expand Up @@ -323,7 +319,7 @@ inline Chain *Problem::chain( int seed )
else
delta -= mLabelPositions.at( tmpsol[seed] )->cost();

for ( i = -1; i < seedNbLp; i++ )
for ( int i = -1; i < seedNbLp; i++ )
{
try
{
Expand Down Expand Up @@ -387,7 +383,7 @@ inline Chain *Problem::chain( int seed )
retainedChain->label = new int[retainedChain->degree];
QLinkedList<ElemTrans *>::iterator current = currentChain.begin();
ElemTrans *move = nullptr;
j = 0;
int j = 0;
while ( current != currentChain.end() )
{
move = *current;
Expand Down Expand Up @@ -426,7 +422,7 @@ inline Chain *Problem::chain( int seed )
newChain->label = new int[newChain->degree];
QLinkedList<ElemTrans *>::iterator current = currentChain.begin();
ElemTrans *move = nullptr;
j = 0;
int j = 0;

while ( current != currentChain.end() )
{
Expand Down Expand Up @@ -487,7 +483,7 @@ inline Chain *Problem::chain( int seed )
retainedChain->label = new int[retainedChain->degree];
QLinkedList<ElemTrans *>::iterator current = currentChain.begin();
ElemTrans *move = nullptr;
j = 0;
int j = 0;
while ( current != currentChain.end() )
{
move = *current;
Expand All @@ -503,9 +499,8 @@ inline Chain *Problem::chain( int seed )
}
}
}
catch ( int i )
catch ( int )
{
Q_UNUSED( i )
conflicts.clear();
}
} // end foreach labelposition
Expand Down
6 changes: 3 additions & 3 deletions src/core/providers/ogr/qgsgeopackageprojectstorage.cpp
Expand Up @@ -255,9 +255,9 @@ bool QgsGeoPackageProjectStorage::writeProject( const QString &uri, QIODevice *d
errCause = _executeSql( projectUri.database, sql );
if ( !errCause.isEmpty() )
{
const QString errCause = QObject::tr( "Unable to insert or update project (project=%1) in the destination table on the database: %2" )
.arg( uri,
errCause );
errCause = QObject::tr( "Unable to insert or update project (project=%1) in the destination table on the database: %2" )
.arg( uri,
errCause );

context.pushMessage( errCause, Qgis::Critical );
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsconditionalstyle.cpp
Expand Up @@ -110,9 +110,9 @@ bool QgsConditionalLayerStyles::readXml( const QDomNode &node, const QgsReadWrit
QString fieldName = fieldel.attribute( QStringLiteral( "fieldname" ) );
QDomNodeList stylenodelist = fieldel.toElement().elementsByTagName( QStringLiteral( "style" ) );
styles.reserve( stylenodelist.count() );
for ( int i = 0; i < stylenodelist.count(); i++ )
for ( int j = 0; j < stylenodelist.count(); j++ )
{
QDomElement styleElm = stylenodelist.at( i ).toElement();
QDomElement styleElm = stylenodelist.at( j ).toElement();
QgsConditionalStyle style = QgsConditionalStyle();
style.readXml( styleElm, context );
styles.append( style );
Expand Down
116 changes: 61 additions & 55 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1064,19 +1064,22 @@ bool QgsCoordinateReferenceSystem::createFromProj( const QString &projString )
// also with parameters containing spaces (e.g. +nadgrids)
// make sure result is trimmed (#5598)
QStringList myParams;
const auto constSplit = myProj4String.split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts );
for ( const QString &param : constSplit )
const QRegExp regExp( "\\s+(?=\\+)" );
{
QString arg = QStringLiteral( "' '||parameters||' ' LIKE %1" ).arg( QgsSqliteUtils::quotedString( QStringLiteral( "% %1 %" ).arg( param.trimmed() ) ) );
if ( param.startsWith( QLatin1String( "+datum=" ) ) )
{
datum = arg;
}
else
const auto constSplit = myProj4String.split( regExp, QString::SkipEmptyParts );
for ( const QString &param : constSplit )
{
sql += delim + arg;
delim = QStringLiteral( " AND " );
myParams << param.trimmed();
QString arg = QStringLiteral( "' '||parameters||' ' LIKE %1" ).arg( QgsSqliteUtils::quotedString( QStringLiteral( "% %1 %" ).arg( param.trimmed() ) ) );
if ( param.startsWith( QLatin1String( "+datum=" ) ) )
{
datum = arg;
}
else
{
sql += delim + arg;
delim = QStringLiteral( " AND " );
myParams << param.trimmed();
}
}
}

Expand All @@ -1095,7 +1098,7 @@ bool QgsCoordinateReferenceSystem::createFromProj( const QString &projString )
{
// Bugfix 8487 : test param lists are equal, except for +datum
QStringList foundParams;
const auto constSplit = myRecord["parameters"].split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts );
const auto constSplit = myRecord["parameters"].split( regExp, QString::SkipEmptyParts );
for ( const QString &param : constSplit )
{
if ( !param.startsWith( QLatin1String( "+datum=" ) ) )
Expand Down Expand Up @@ -3212,65 +3215,68 @@ bool QgsCoordinateReferenceSystem::syncDatumTransform( const QString &dbPath )
};

QString update = QStringLiteral( "UPDATE tbl_datum_transform SET " );
QString insert, values;

int n = CSLCount( fieldnames );

QString insert;
const int n = CSLCount( fieldnames );
int idxid = -1, idxrx = -1, idxry = -1, idxrz = -1, idxmcode = -1;
for ( unsigned int i = 0; i < sizeof( map ) / sizeof( *map ); i++ )
{
bool last = i == sizeof( map ) / sizeof( *map ) - 1;

map[i].idx = CSLFindString( fieldnames, map[i].src );
if ( map[i].idx < 0 )
{
qWarning( "field %s not found", map[i].src );
CSLDestroy( fieldnames );
fclose( fp );
return false;
}

if ( strcmp( map[i].src, "COORD_OP_CODE" ) == 0 )
idxid = i;
if ( strcmp( map[i].src, "RX" ) == 0 )
idxrx = i;
if ( strcmp( map[i].src, "RY" ) == 0 )
idxry = i;
if ( strcmp( map[i].src, "RZ" ) == 0 )
idxrz = i;
if ( strcmp( map[i].src, "COORD_OP_METHOD_CODE" ) == 0 )
idxmcode = i;
{
QString values;

if ( i > 0 )
for ( unsigned int i = 0; i < sizeof( map ) / sizeof( *map ); i++ )
{
insert += ',';
values += ',';
bool last = i == sizeof( map ) / sizeof( *map ) - 1;

if ( last )
map[i].idx = CSLFindString( fieldnames, map[i].src );
if ( map[i].idx < 0 )
{
update += QLatin1String( " WHERE " );
qWarning( "field %s not found", map[i].src );
CSLDestroy( fieldnames );
fclose( fp );
return false;
}
else

if ( strcmp( map[i].src, "COORD_OP_CODE" ) == 0 )
idxid = i;
if ( strcmp( map[i].src, "RX" ) == 0 )
idxrx = i;
if ( strcmp( map[i].src, "RY" ) == 0 )
idxry = i;
if ( strcmp( map[i].src, "RZ" ) == 0 )
idxrz = i;
if ( strcmp( map[i].src, "COORD_OP_METHOD_CODE" ) == 0 )
idxmcode = i;

if ( i > 0 )
{
update += ',';
insert += ',';
values += ',';

if ( last )
{
update += QLatin1String( " WHERE " );
}
else
{
update += ',';
}
}

update += QStringLiteral( "%1=%%2" ).arg( map[i].dst ).arg( i + 1 );

insert += map[i].dst;
values += QStringLiteral( "%%1" ).arg( i + 1 );
}

update += QStringLiteral( "%1=%%2" ).arg( map[i].dst ).arg( i + 1 );
insert = "INSERT INTO tbl_datum_transform(" + insert + ") VALUES (" + values + ')';

insert += map[i].dst;
values += QStringLiteral( "%%1" ).arg( i + 1 );
Q_ASSERT( idxid >= 0 );
Q_ASSERT( idxrx >= 0 );
Q_ASSERT( idxry >= 0 );
Q_ASSERT( idxrz >= 0 );
}

insert = "INSERT INTO tbl_datum_transform(" + insert + ") VALUES (" + values + ')';

CSLDestroy( fieldnames );

Q_ASSERT( idxid >= 0 );
Q_ASSERT( idxrx >= 0 );
Q_ASSERT( idxry >= 0 );
Q_ASSERT( idxrz >= 0 );

sqlite3_database_unique_ptr database;
int openResult = database.open( dbPath );
if ( openResult != SQLITE_OK )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdatasourceuri.cpp
Expand Up @@ -93,7 +93,7 @@ QgsDataSourceUri::QgsDataSourceUri( const QString &u )
{
i++;

int start = i;
start = i;
while ( i < uri.length() && uri[i] != ')' )
{
if ( uri[i] == '\\' )
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsexpressionsorter.h
Expand Up @@ -141,21 +141,21 @@ class QgsExpressionSorter

QVector<QgsIndexedFeature> indexedFeatures;

QgsIndexedFeature indexedFeature;
QgsIndexedFeature indexedFeatureToAppend;

for ( const QgsFeature &f : qgis::as_const( features ) )
{
indexedFeature.mIndexes.resize( mPreparedOrderBys.size() );
indexedFeature.mFeature = f;
indexedFeatureToAppend.mIndexes.resize( mPreparedOrderBys.size() );
indexedFeatureToAppend.mFeature = f;

expressionContext->setFeature( indexedFeature.mFeature );
expressionContext->setFeature( indexedFeatureToAppend.mFeature );

int i = 0;
for ( const QgsFeatureRequest::OrderByClause &orderBy : qgis::as_const( mPreparedOrderBys ) )
{
indexedFeature.mIndexes.replace( i++, orderBy.expression().evaluate( expressionContext ) );
indexedFeatureToAppend.mIndexes.replace( i++, orderBy.expression().evaluate( expressionContext ) );
}
indexedFeatures.append( indexedFeature );
indexedFeatures.append( indexedFeatureToAppend );
}

delete expressionContext->popScope();
Expand Down
1 change: 0 additions & 1 deletion src/core/qgsfontutils.cpp
Expand Up @@ -180,7 +180,6 @@ bool QgsFontUtils::updateFontViaStyle( QFont &f, const QString &fontstyle, bool
// fallback to first style found that works
if ( !foundmatch )
{
const auto constFamily = fontDB.styles( f.family() );
for ( const QString &style : constFamily )
{
styledfont = fontDB.font( f.family(), style, defaultSize );
Expand Down

0 comments on commit 1b88cc3

Please sign in to comment.