Skip to content
Permalink
Browse files

Fix cppcheck nullPointer/nullPointerRedundantCheck warnings in src/core/

Found with
~/cppcheck/cppcheck --enable=all --inconclusive ../src/core --library=$HOME/cppcheck/cfg/qt.cfg -j 8 -DSIP_OUT 2>&1 | grep nullPointer

Mostly false positives or indeed redundant check, except perhaps in
QgsSingleBandPseudoColorRenderer::toSld() where a null pointer dereference
could occur in case of failed dynamic_cast.
  • Loading branch information
rouault authored and nyalldawson committed Jan 29, 2020
1 parent 7b0bcfa commit 385d3ecd7d41c42466f7d7c799e4fefc6d6585d4
@@ -908,7 +908,7 @@ void QgsDxfExport::writePoint( const QgsPoint &pt, const QString &layer, const Q
const QgsMarkerSymbolLayer *msl = dynamic_cast< const QgsMarkerSymbolLayer * >( symbolLayer );
if ( msl && symbol )
{
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScale, msl->sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
if ( msl->writeDxf( *this, mapUnitScaleFactor( mSymbologyScale, msl->sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
{
return;
}
@@ -743,16 +743,18 @@ static QVariant fcnAggregateRelation( const QVariantList &values, const QgsExpre
}
}

if ( !context->hasFeature() )
return QVariant();
QgsFeature f = context->feature();

FEAT_FROM_CONTEXT( context, f )
parameters.filter = relation.getRelatedFeaturesFilter( f );

QString cacheKey = QStringLiteral( "relagg:%1:%2:%3:%4:%5" ).arg( vl->id(),
QString::number( static_cast< int >( aggregate ) ),
subExpression,
parameters.filter,
orderBy );
if ( context && context->hasCachedValue( cacheKey ) )
if ( context->hasCachedValue( cacheKey ) )
return context->cachedValue( cacheKey );

QVariant result;
@@ -769,8 +771,7 @@ static QVariant fcnAggregateRelation( const QVariantList &values, const QgsExpre
}

// cache value
if ( context )
context->setCachedValue( cacheKey, result );
context->setCachedValue( cacheKey, result );
return result;
}

@@ -854,7 +855,7 @@ static QVariant fcnAggregateGeneric( QgsAggregateCalculator::Aggregate aggregate
subExpression,
parameters.filter,
orderBy );
if ( context && context->hasCachedValue( cacheKey ) )
if ( context->hasCachedValue( cacheKey ) )
return context->cachedValue( cacheKey );

QVariant result;
@@ -870,8 +871,7 @@ static QVariant fcnAggregateGeneric( QgsAggregateCalculator::Aggregate aggregate
}

// cache value
if ( context )
context->setCachedValue( cacheKey, result );
context->setCachedValue( cacheKey, result );
return result;
}

@@ -1156,6 +1156,7 @@ void QgsDataDefinedSizeLegendNode::cacheImage() const
if ( !context )
{
context.reset( new QgsRenderContext );
Q_ASSERT( context ); // to make cppcheck happy
context->setScaleFactor( 96 / 25.4 );
}
mImage = mSettings->collapsedLegendImage( *context );
@@ -676,6 +676,7 @@ QgsRasterBlock *QgsGdalProvider::block( int bandNo, const QgsRectangle &extent,
return block.release();
}
// apply scale and offset
Q_ASSERT( block ); // to make cppcheck happy
block->applyScaleOffset( bandScale( bandNo ), bandOffset( bandNo ) );
block->applyNoDataValues( userNoDataValues( bandNo ) );
return block.release();
@@ -166,6 +166,7 @@ QgsRasterBlock *QgsPalettedRasterRenderer::block( int, QgsRectangle const &exte

//use direct data access instead of QgsRasterBlock::setValue
//because of performance
Q_ASSERT( outputBlock ); // to make cppcheck happy
unsigned int *outputData = ( unsigned int * )( outputBlock->bits() );

qgssize rasterSize = ( qgssize )width * height;
@@ -368,20 +368,20 @@ void QgsSingleBandPseudoColorRenderer::toSld( QDomDocument &doc, QDomElement &el
// basing on interpolation algorithm of the raster shader
QString rampType = QStringLiteral( "ramp" );
const QgsColorRampShader *rampShader = dynamic_cast<const QgsColorRampShader *>( mShader->rasterShaderFunction() );
if ( rampShader )
if ( !rampShader )
return;

switch ( rampShader->colorRampType() )
{
switch ( rampShader->colorRampType() )
{
case ( QgsColorRampShader::Exact ):
rampType = QStringLiteral( "values" );
break;
case ( QgsColorRampShader::Discrete ):
rampType = QStringLiteral( "intervals" );
break;
case ( QgsColorRampShader::Interpolated ):
rampType = QStringLiteral( "ramp" );
break;
}
case ( QgsColorRampShader::Exact ):
rampType = QStringLiteral( "values" );
break;
case ( QgsColorRampShader::Discrete ):
rampType = QStringLiteral( "intervals" );
break;
case ( QgsColorRampShader::Interpolated ):
rampType = QStringLiteral( "ramp" );
break;
}

colorMapElem.setAttribute( QStringLiteral( "type" ), rampType );

0 comments on commit 385d3ec

Please sign in to comment.
You can’t perform that action at this time.