Skip to content

Commit 8107009

Browse files
committedApr 13, 2023
Fix some more cppcheck nullptr redundant checks
1 parent 04d9841 commit 8107009

File tree

8 files changed

+14
-13
lines changed

8 files changed

+14
-13
lines changed
 

‎src/app/georeferencer/qgsgeorefmainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void QgsGeoreferencerMainWindow::openLayer( Qgis::LayerType layerType, const QSt
380380
mCanvas->refresh();
381381
QgisApp::instance()->mapCanvas()->refresh();
382382

383-
const bool hasExistingReference = mLayer->crs().isValid();
383+
const bool hasExistingReference = mLayer ? mLayer->crs().isValid() : false;
384384
mActionLinkGeorefToQgis->setEnabled( hasExistingReference );
385385
mActionLinkQGisToGeoref->setEnabled( hasExistingReference );
386386
if ( !hasExistingReference )

‎src/app/maptools/qgsmaptoolshapecircularstringabstract.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void QgsMapToolShapeCircularStringAbstract::undo()
6565
const int lastPositionCompleteCircularString = mPoints.size() - 1 - ( mPoints.size() + 1 ) % 2 ;
6666

6767
geomTempRubberBand->setPoints( mPoints.mid( lastPositionCompleteCircularString ) );
68-
mTempRubberBand->setGeometry( geomTempRubberBand.release() );
68+
if ( mTempRubberBand )
69+
mTempRubberBand->setGeometry( geomTempRubberBand.release() );
6970

7071
if ( mRubberBand )
7172
{

‎src/app/pointcloud/qgspointcloudlayerproperties.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
#include "qgsnative.h"
2525
#include "qgsapplication.h"
2626
#include "qgsmetadatawidget.h"
27-
#include "qgsmaplayerloadstyledialog.h"
2827
#include "qgsmaplayerconfigwidgetfactory.h"
2928
#include "qgsmaplayerconfigwidget.h"
3029
#include "qgspointcloudattributemodel.h"
3130
#include "qgsdatumtransformdialog.h"
32-
#include "qgspointcloudlayerelevationproperties.h"
3331
#include "qgspointcloudquerybuilder.h"
34-
#include "qgspointcloudrenderer.h"
3532

3633
#include <QFileDialog>
3734
#include <QMenu>
@@ -177,7 +174,7 @@ void QgsPointCloudLayerProperties::apply()
177174

178175
mBackupCrs = mLayer->crs();
179176

180-
for ( QgsMapLayerConfigWidget *w : mConfigWidgets )
177+
for ( QgsMapLayerConfigWidget *w : std::as_const( mConfigWidgets ) )
181178
w->apply();
182179

183180
mLayer->triggerRepaint();
@@ -223,11 +220,10 @@ void QgsPointCloudLayerProperties::syncToLayer()
223220
txtSubsetSQL->setReadOnly( true );
224221
txtSubsetSQL->setCaretWidth( 0 );
225222
txtSubsetSQL->setCaretLineVisible( false );
226-
pbnQueryBuilder->setEnabled( mLayer &&
227-
mLayer->dataProvider() &&
223+
pbnQueryBuilder->setEnabled( mLayer->dataProvider() &&
228224
mLayer->dataProvider()->supportsSubsetString() );
229225

230-
for ( QgsMapLayerConfigWidget *w : mConfigWidgets )
226+
for ( QgsMapLayerConfigWidget *w : std::as_const( mConfigWidgets ) )
231227
w->syncToLayer( mLayer );
232228

233229
mStatisticsCalculationWarningLabel->setHidden( mLayer->statisticsCalculationState() != QgsPointCloudLayer::PointCloudStatisticsCalculationState::Calculated );

‎src/app/qgsmaptoolselectutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ QgsFeatureIds QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::search( std::s
645645

646646
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::onSearchFinished()
647647
{
648-
if ( mFutureWatcher && !mFutureWatcher->isFinished() )
648+
if ( !mFutureWatcher || !mFutureWatcher->isFinished() )
649649
return;
650650

651651
mAllFeatureIds = mFutureWatcher->result();

‎src/core/layout/qgslayoutitemelevationprofile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ void QgsLayoutItemElevationProfile::paint( QPainter *painter, const QStyleOption
619619

620620
QSizeF layoutSize = mLayout->convertToLayoutUnits( sizeWithUnits() );
621621

622-
if ( mLayout && mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagLosslessImageRendering )
622+
if ( mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagLosslessImageRendering )
623623
painter->setRenderHint( QPainter::LosslessImageRendering, true );
624624

625625
QgsRenderContext rc = QgsLayoutUtils::createRenderContextForLayout( mLayout, painter );

‎src/core/layout/qgslayoutitemlabel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void QgsLayoutItemLabel::contentChanged()
191191
//set this to true after html is loaded.
192192
mHtmlLoaded = false;
193193

194-
const QUrl baseUrl = QUrl::fromLocalFile( mLayout->project()->absoluteFilePath() );
194+
const QUrl baseUrl = mLayout ? QUrl::fromLocalFile( mLayout->project()->absoluteFilePath() ) : QUrl();
195195
mWebPage->mainFrame()->setHtml( textToDraw, baseUrl );
196196

197197
//For very basic html labels with no external assets, the html load will already be

‎src/core/maprenderer/qgsmaprenderersequentialjob.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void QgsMapRendererSequentialJob::cancel()
8585
QgsDebugMsgLevel( QStringLiteral( "sequential - cancel internal" ), 5 );
8686
mInternalJob->cancel();
8787

88+
// cppcheck-suppress nullPointerRedundantCheck
8889
Q_ASSERT( !mInternalJob && !mPainter );
8990
}
9091

‎src/core/symbology/qgssymbol.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,13 @@ QgsSymbol *QgsSymbol::defaultSymbol( Qgis::GeometryType geomType )
737737
break;
738738
default:
739739
QgsDebugMsg( QStringLiteral( "unknown layer's geometry type" ) );
740-
return nullptr;
740+
break;
741741
}
742742
}
743743

744+
if ( !s )
745+
return nullptr;
746+
744747
// set opacity
745748
s->setOpacity( QgsProject::instance()->styleSettings()->defaultSymbolOpacity() );
746749

0 commit comments

Comments
 (0)
Please sign in to comment.