Skip to content

Commit

Permalink
Fix coverity null pointer dereference warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 5, 2017
1 parent 75c9980 commit fa5a831
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmpackage.cpp
Expand Up @@ -101,7 +101,7 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap &parameters
multiStepFeedback.setCurrentStep( i );
i++;

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

if ( !layer )
{
Expand Down
9 changes: 4 additions & 5 deletions src/app/layout/qgslayoutlabelwidget.cpp
Expand Up @@ -29,6 +29,8 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
: QgsLayoutItemBaseWidget( nullptr, label )
, mLabel( label )
{
Q_ASSERT( mLabel );

setupUi( this );
connect( mHtmlCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged );
connect( mTextEdit, &QPlainTextEdit::textChanged, this, &QgsLayoutLabelWidget::mTextEdit_textChanged );
Expand Down Expand Up @@ -56,11 +58,8 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
mMarginXDoubleSpinBox->setClearValue( 0.0 );
mMarginYDoubleSpinBox->setClearValue( 0.0 );

if ( mLabel )
{
setGuiElementValues();
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
}
setGuiElementValues();
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );

connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutLabelWidget::fontChanged );
connect( mJustifyRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::justifyClicked );
Expand Down
20 changes: 9 additions & 11 deletions src/app/layout/qgslayoutlegendwidget.cpp
Expand Up @@ -61,6 +61,8 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
: QgsLayoutItemBaseWidget( nullptr, legend )
, mLegend( legend )
{
Q_ASSERT( mLegend );

setupUi( this );
connect( mWrapCharLineEdit, &QLineEdit::textChanged, this, &QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged );
connect( mTitleLineEdit, &QLineEdit::textChanged, this, &QgsLayoutLegendWidget::mTitleLineEdit_textChanged );
Expand Down Expand Up @@ -120,8 +122,7 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend )
mRasterStrokeColorButton->setAllowOpacity( true );
mRasterStrokeColorButton->setContext( QStringLiteral( "composer " ) );

if ( legend )
mMapComboBox->setCurrentLayout( legend->layout() );
mMapComboBox->setCurrentLayout( legend->layout() );
mMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
connect( mMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutLegendWidget::composerMapChanged );

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

mItemTreeView->setHeaderHidden( true );

if ( legend )
{
mItemTreeView->setModel( legend->model() );
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );
mItemTreeView->setModel( legend->model() );
mItemTreeView->setMenuProvider( new QgsLayoutLegendMenuProvider( mItemTreeView, this ) );
connect( legend, &QgsLayoutObject::changed, this, &QgsLayoutLegendWidget::setGuiElements );

#if 0 //TODO
// connect atlas state to the filter legend by atlas checkbox
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
// connect atlas state to the filter legend by atlas checkbox
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
connect( &legend->composition()->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
#endif
}

registerDataDefinedButton( mLegendTitleDDBtn, QgsLayoutObject::LegendTitle );
registerDataDefinedButton( mColumnsDDBtn, QgsLayoutObject::LegendColumnCount );
Expand Down
27 changes: 13 additions & 14 deletions src/app/layout/qgslayoutmapwidget.cpp
Expand Up @@ -35,6 +35,8 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
: QgsLayoutItemBaseWidget( nullptr, item )
, mMapItem( item )
{
Q_ASSERT( mMapItem );

setupUi( this );
connect( mScaleLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
connect( mSetToMapCanvasExtentButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked );
Expand Down Expand Up @@ -108,24 +110,21 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )

mOverviewFrameMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );

if ( item )
{
connect( item, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
connect( item, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );

#if 0 //TODO
QgsAtlasComposition *atlas = atlasComposition();
if ( atlas )
{
connect( atlas, &QgsAtlasComposition::coverageLayerChanged,
this, &QgsLayoutMapWidget::atlasLayerChanged );
connect( atlas, &QgsAtlasComposition::toggled, this, &QgsLayoutMapWidget::compositionAtlasToggled );
QgsAtlasComposition *atlas = atlasComposition();
if ( atlas )
{
connect( atlas, &QgsAtlasComposition::coverageLayerChanged,
this, &QgsLayoutMapWidget::atlasLayerChanged );
connect( atlas, &QgsAtlasComposition::toggled, this, &QgsLayoutMapWidget::compositionAtlasToggled );

compositionAtlasToggled( atlas->enabled() );
}
#endif
mOverviewFrameMapComboBox->setCurrentLayout( item->layout() );
mOverviewFrameStyleButton->registerExpressionContextGenerator( item );
compositionAtlasToggled( atlas->enabled() );
}
#endif
mOverviewFrameMapComboBox->setCurrentLayout( item->layout() );
mOverviewFrameStyleButton->registerExpressionContextGenerator( item );

connect( mOverviewFrameMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutMapWidget::overviewMapChanged );
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsLayoutMapWidget::mapCrsChanged );
Expand Down
10 changes: 5 additions & 5 deletions src/app/layout/qgslayoutshapewidget.cpp
Expand Up @@ -25,6 +25,8 @@ QgsLayoutShapeWidget::QgsLayoutShapeWidget( QgsLayoutItemShape *shape )
: QgsLayoutItemBaseWidget( nullptr, shape )
, mShape( shape )
{
Q_ASSERT( mShape );

setupUi( this );
connect( mShapeComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutShapeWidget::mShapeComboBox_currentIndexChanged );
connect( mCornerRadiusSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutShapeWidget::mCornerRadiusSpinBox_valueChanged );
Expand Down Expand Up @@ -52,11 +54,9 @@ QgsLayoutShapeWidget::QgsLayoutShapeWidget( QgsLayoutItemShape *shape )

blockAllSignals( false );

if ( mShape )
{
connect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues );
mShapeStyleButton->registerExpressionContextGenerator( mShape );
}
connect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues );
mShapeStyleButton->registerExpressionContextGenerator( mShape );

connect( mShapeStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutShapeWidget::symbolChanged );
connect( mRadiusUnitsComboBox, &QgsLayoutUnitsComboBox::changed, this, &QgsLayoutShapeWidget::radiusUnitsChanged );

Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutmultiframe.cpp
Expand Up @@ -143,7 +143,7 @@ void QgsLayoutMultiFrame::recalculateFrameSizes()
}

//at end of frames but there is still content left. Add other pages if ResizeMode ==
if ( mResizeMode != UseExistingFrames )
if ( currentItem && mResizeMode != UseExistingFrames )
{
while ( ( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight )
{
Expand Down
3 changes: 2 additions & 1 deletion tests/src/core/testqgsdxfexport.cpp
Expand Up @@ -301,7 +301,8 @@ bool TestQgsDxfExport::fileContainsText( const QString &path, const QString &tex
{
QStringList searchLines = text.split( '\n' );
QFile file( path );
QVERIFY( file.open( QIODevice::ReadOnly ) );
if ( !file.open( QIODevice::ReadOnly ) )
return false;
QTextStream in( &file );
QString line;
do
Expand Down

0 comments on commit fa5a831

Please sign in to comment.