#14275 Fix crash in multi-plot axis alignment when a plot lacks the queried axis

QwtPlot::axisWidget() returns NULL for an axis id that is not valid for a
given plot. RiuMultiPlotPage::alignAxis dereferenced the returned
QwtScaleWidget without a null check, causing a segmentation fault when a
plot in the grid does not have the queried axis. Guard the pointer in both
alignment loops, matching the existing null-check style in the function.
This commit is contained in:
Magne Sjaastad committed 2026-06-22 15:29:44 +02:00
1 parent 50daba9e27
commit 06cafed9bc
1 file changed
+12 -10
@@ -1154,13 +1154,14 @@ void RiuMultiPlotPage::alignAxis( QwtAxisId axis, int targetRowOrColumn, std::fu
if ( riuQwtPlotWidget )
{
QwtPlot* p = riuQwtPlotWidget->qwtPlot();
if ( p )
if ( QwtPlot* p = riuQwtPlotWidget->qwtPlot() )
{
QwtScaleWidget* scaleWidget = p->axisWidget( axis );
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent( 0.0 );
maxExtent = std::max( sd->extent( scaleWidget->font() ), maxExtent );
if ( QwtScaleWidget* scaleWidget = p->axisWidget( axis ) )
{
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent( 0.0 );
maxExtent = std::max( sd->extent( scaleWidget->font() ), maxExtent );
}
}
}
}
@@ -1179,11 +1180,12 @@ void RiuMultiPlotPage::alignAxis( QwtAxisId axis, int targetRowOrColumn, std::fu
RiuQwtPlotWidget* riuQwtPlotWidget = dynamic_cast<RiuQwtPlotWidget*>( plotWidget );
if ( riuQwtPlotWidget )
{
QwtPlot* p = riuQwtPlotWidget->qwtPlot();
if ( p )
if ( QwtPlot* p = riuQwtPlotWidget->qwtPlot() )
{
QwtScaleWidget* scaleWidget = p->axisWidget( axis );
scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
if ( QwtScaleWidget* scaleWidget = p->axisWidget( axis ) )
{
scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
}
}
}
}