Skip to content

Commit fa5a831

Browse files
committed
Fix coverity null pointer dereference warnings
1 parent 75c9980 commit fa5a831

7 files changed

+35
-38
lines changed

src/analysis/processing/qgsalgorithmpackage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap &parameters
101101
multiStepFeedback.setCurrentStep( i );
102102
i++;
103103

104-
feedback->pushInfo( QObject::tr( "Packaging layer %1/%2: %3" ).arg( i ).arg( layers.count() ).arg( layer->name() ) );
104+
feedback->pushInfo( QObject::tr( "Packaging layer %1/%2: %3" ).arg( i ).arg( layers.count() ).arg( layer ? layer->name() : QString() ) );
105105

106106
if ( !layer )
107107
{

src/app/layout/qgslayoutlabelwidget.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
2929
: QgsLayoutItemBaseWidget( nullptr, label )
3030
, mLabel( label )
3131
{
32+
Q_ASSERT( mLabel );
33+
3234
setupUi( this );
3335
connect( mHtmlCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged );
3436
connect( mTextEdit, &QPlainTextEdit::textChanged, this, &QgsLayoutLabelWidget::mTextEdit_textChanged );
@@ -56,11 +58,8 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
5658
mMarginXDoubleSpinBox->setClearValue( 0.0 );
5759
mMarginYDoubleSpinBox->setClearValue( 0.0 );
5860

59-
if ( mLabel )
60-
{
61-
setGuiElementValues();
62-
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
63-
}
61+
setGuiElementValues();
62+
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
6463

6564
connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutLabelWidget::fontChanged );
6665
connect( mJustifyRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::justifyClicked );

src/app/layout/qgslayoutlegendwidget.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
6161
: QgsLayoutItemBaseWidget( nullptr, legend )
6262
, mLegend( legend )
6363
{
64+
Q_ASSERT( mLegend );
65+
6466
setupUi( this );
6567
connect( mWrapCharLineEdit, &QLineEdit::textChanged, this, &QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged );
6668
connect( mTitleLineEdit, &QLineEdit::textChanged, this, &QgsLayoutLegendWidget::mTitleLineEdit_textChanged );
@@ -120,8 +122,7 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
120122
mRasterStrokeColorButton->setAllowOpacity( true );
121123
mRasterStrokeColorButton->setContext( QStringLiteral( "composer " ) );
122124

123-
if ( legend )
124-
mMapComboBox->setCurrentLayout( legend->layout() );
125+
mMapComboBox->setCurrentLayout( legend->layout() );
125126
mMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
126127
connect( mMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutLegendWidget::composerMapChanged );
127128

@@ -131,18 +132,15 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
131132

132133
mItemTreeView->setHeaderHidden( true );
133134

134-
if ( legend )
135-
{
136-
mItemTreeView->setModel( legend->model() );
137-
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
138-
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );
135+
mItemTreeView->setModel( legend->model() );
136+
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
137+
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );
139138

140139
#if 0 //TODO
141-
// connect atlas state to the filter legend by atlas checkbox
142-
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
143-
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
140+
// connect atlas state to the filter legend by atlas checkbox
141+
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
142+
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
144143
#endif
145-
}
146144

147145
registerDataDefinedButton( mLegendTitleDDBtn, QgsLayoutObject::LegendTitle );
148146
registerDataDefinedButton( mColumnsDDBtn, QgsLayoutObject::LegendColumnCount );

src/app/layout/qgslayoutmapwidget.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
3535
: QgsLayoutItemBaseWidget( nullptr, item )
3636
, mMapItem( item )
3737
{
38+
Q_ASSERT( mMapItem );
39+
3840
setupUi( this );
3941
connect( mScaleLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
4042
connect( mSetToMapCanvasExtentButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked );
@@ -108,24 +110,21 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
108110

109111
mOverviewFrameMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
110112

111-
if ( item )
112-
{
113-
connect( item, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
113+
connect( item, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
114114

115115
#if 0 //TODO
116-
QgsAtlasComposition *atlas = atlasComposition();
117-
if ( atlas )
118-
{
119-
connect( atlas, &QgsAtlasComposition::coverageLayerChanged,
120-
this, &QgsLayoutMapWidget::atlasLayerChanged );
121-
connect( atlas, &QgsAtlasComposition::toggled, this, &QgsLayoutMapWidget::compositionAtlasToggled );
116+
QgsAtlasComposition *atlas = atlasComposition();
117+
if ( atlas )
118+
{
119+
connect( atlas, &QgsAtlasComposition::coverageLayerChanged,
120+
this, &QgsLayoutMapWidget::atlasLayerChanged );
121+
connect( atlas, &QgsAtlasComposition::toggled, this, &QgsLayoutMapWidget::compositionAtlasToggled );
122122

123-
compositionAtlasToggled( atlas->enabled() );
124-
}
125-
#endif
126-
mOverviewFrameMapComboBox->setCurrentLayout( item->layout() );
127-
mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
123+
compositionAtlasToggled( atlas->enabled() );
128124
}
125+
#endif
126+
mOverviewFrameMapComboBox->setCurrentLayout( item->layout() );
127+
mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
129128

130129
connect( mOverviewFrameMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutMapWidget::overviewMapChanged );
131130
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsLayoutMapWidget::mapCrsChanged );

src/app/layout/qgslayoutshapewidget.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ QgsLayoutShapeWidget::QgsLayoutShapeWidget( QgsLayoutItemShape *shape )
2525
: QgsLayoutItemBaseWidget( nullptr, shape )
2626
, mShape( shape )
2727
{
28+
Q_ASSERT( mShape );
29+
2830
setupUi( this );
2931
connect( mShapeComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutShapeWidget::mShapeComboBox_currentIndexChanged );
3032
connect( mCornerRadiusSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutShapeWidget::mCornerRadiusSpinBox_valueChanged );
@@ -52,11 +54,9 @@ QgsLayoutShapeWidget::QgsLayoutShapeWidget( QgsLayoutItemShape *shape )
5254

5355
blockAllSignals( false );
5456

55-
if ( mShape )
56-
{
57-
connect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues );
58-
mShapeStyleButton->registerExpressionContextGenerator( mShape );
59-
}
57+
connect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues );
58+
mShapeStyleButton->registerExpressionContextGenerator( mShape );
59+
6060
connect( mShapeStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutShapeWidget::symbolChanged );
6161
connect( mRadiusUnitsComboBox, &QgsLayoutUnitsComboBox::changed, this, &QgsLayoutShapeWidget::radiusUnitsChanged );
6262

src/core/layout/qgslayoutmultiframe.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void QgsLayoutMultiFrame::recalculateFrameSizes()
143143
}
144144

145145
//at end of frames but there is still content left. Add other pages if ResizeMode ==
146-
if ( mResizeMode != UseExistingFrames )
146+
if ( currentItem && mResizeMode != UseExistingFrames )
147147
{
148148
while ( ( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight )
149149
{

tests/src/core/testqgsdxfexport.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ bool TestQgsDxfExport::fileContainsText( const QString &path, const QString &tex
301301
{
302302
QStringList searchLines = text.split( '\n' );
303303
QFile file( path );
304-
QVERIFY( file.open( QIODevice::ReadOnly ) );
304+
if ( !file.open( QIODevice::ReadOnly ) )
305+
return false;
305306
QTextStream in( &file );
306307
QString line;
307308
do

0 commit comments

Comments
 (0)