#7361 Janitor : Guard null pointer access

This commit is contained in:
Magne Sjaastad 2021-02-24 20:39:14 +01:00
parent 1a28e71b68
commit ce2dd46a2e
6 changed files with 8 additions and 29 deletions

View File

@ -984,7 +984,6 @@ void RimWellAllocationPlot::updateFormationNamesData() const
for ( size_t i = 0; i < m_accumulatedWellFlowPlot->plotCount(); ++i ) for ( size_t i = 0; i < m_accumulatedWellFlowPlot->plotCount(); ++i )
{ {
RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( m_accumulatedWellFlowPlot->plotByIndex( i ) ); RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( m_accumulatedWellFlowPlot->plotByIndex( i ) );
CAF_ASSERT( track );
if ( track ) if ( track )
{ {
track->setAndUpdateSimWellFormationNamesData( m_case, m_wellName ); track->setAndUpdateSimWellFormationNamesData( m_case, m_wellName );

View File

@ -233,7 +233,6 @@ void RimWellPltPlot::updateFormationsOnPlot() const
RimWellPath* wellPath = proj->wellPathByName( m_wellPathName ); RimWellPath* wellPath = proj->wellPathByName( m_wellPathName );
RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( track );
if ( track ) if ( track )
{ {
RimCase* formationNamesCase = track->formationNamesCase(); RimCase* formationNamesCase = track->formationNamesCase();
@ -484,8 +483,6 @@ public:
void RimWellPltPlot::syncCurvesFromUiSelection() void RimWellPltPlot::syncCurvesFromUiSelection()
{ {
RimWellLogTrack* plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( !plotTrack ) return; if ( !plotTrack ) return;
const std::set<RiaRftPltCurveDefinition>& curveDefs = selectedCurveDefs(); const std::set<RiaRftPltCurveDefinition>& curveDefs = selectedCurveDefs();
@ -890,7 +887,6 @@ void RimWellPltPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
if ( changedField == &m_wellPathName ) if ( changedField == &m_wellPathName )
{ {
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
plotTrack->deleteAllCurves(); plotTrack->deleteAllCurves();
@ -934,7 +930,6 @@ void RimWellPltPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
syncCurvesFromUiSelection(); syncCurvesFromUiSelection();
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
plotTrack->setAutoScaleXEnabled( true ); plotTrack->setAutoScaleXEnabled( true );
@ -948,7 +943,6 @@ void RimWellPltPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
syncCurvesFromUiSelection(); syncCurvesFromUiSelection();
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
plotTrack->setAutoScaleXEnabled( true ); plotTrack->setAutoScaleXEnabled( true );
@ -987,7 +981,6 @@ void RimWellPltPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
if ( plotCount() > 0 ) if ( plotCount() > 0 )
{ {
RimWellLogTrack* const track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( track );
if ( track ) if ( track )
{ {
track->uiOrderingForRftPltFormations( uiOrdering ); track->uiOrderingForRftPltFormations( uiOrdering );
@ -1105,7 +1098,6 @@ void RimWellPltPlot::onLoadDataAndUpdate()
if ( plotCount() > 0 ) if ( plotCount() > 0 )
{ {
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
plotTrack->setAnnotationType( RiuPlotAnnotationTool::RegionAnnotationType::FORMATION_ANNOTATIONS ); plotTrack->setAnnotationType( RiuPlotAnnotationTool::RegionAnnotationType::FORMATION_ANNOTATIONS );

View File

@ -192,7 +192,6 @@ void RimWellRftPlot::updateFormationsOnPlot() const
RimCase* formationNamesCase = nullptr; RimCase* formationNamesCase = nullptr;
RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( track );
if ( track ) if ( track )
{ {
formationNamesCase = track->formationNamesCase(); formationNamesCase = track->formationNamesCase();
@ -395,8 +394,6 @@ void RimWellRftPlot::updateEditorsFromCurves()
void RimWellRftPlot::syncCurvesFromUiSelection() void RimWellRftPlot::syncCurvesFromUiSelection()
{ {
RimWellLogTrack* plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( !plotTrack ) return; if ( !plotTrack ) return;
std::set<RiaRftPltCurveDefinition> allCurveDefs = selectedCurveDefs(); std::set<RiaRftPltCurveDefinition> allCurveDefs = selectedCurveDefs();
@ -460,7 +457,6 @@ std::set<RiaRftPltCurveDefinition> RimWellRftPlot::curveDefsFromCurves() const
std::set<RiaRftPltCurveDefinition> curveDefs; std::set<RiaRftPltCurveDefinition> curveDefs;
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
for ( RimWellLogCurve* const curve : plotTrack->curves() ) for ( RimWellLogCurve* const curve : plotTrack->curves() )
@ -481,7 +477,6 @@ void RimWellRftPlot::updateCurvesInPlot( const std::set<RiaRftPltCurveDefinition
const QString simWellName = associatedSimWellName(); const QString simWellName = associatedSimWellName();
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( !plotTrack ) return; if ( !plotTrack ) return;
// Delete curves // Delete curves
@ -966,7 +961,6 @@ void RimWellRftPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
if ( plotCount() > 0 ) if ( plotCount() > 0 )
{ {
RimWellLogTrack* const track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const track = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( track );
if ( track ) if ( track )
{ {
track->uiOrderingForRftPltFormations( uiOrdering ); track->uiOrderingForRftPltFormations( uiOrdering );
@ -1056,7 +1050,6 @@ void RimWellRftPlot::onLoadDataAndUpdate()
if ( plotCount() > 0 ) if ( plotCount() > 0 )
{ {
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
plotTrack->setAnnotationType( RiuPlotAnnotationTool::RegionAnnotationType::FORMATION_ANNOTATIONS ); plotTrack->setAnnotationType( RiuPlotAnnotationTool::RegionAnnotationType::FORMATION_ANNOTATIONS );
@ -1127,7 +1120,6 @@ void RimWellRftPlot::assignWellPathToExtractionCurves()
if ( wellPath ) if ( wellPath )
{ {
RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) ); RimWellLogTrack* const plotTrack = dynamic_cast<RimWellLogTrack*>( plotByIndex( 0 ) );
CAF_ASSERT( plotTrack );
if ( plotTrack ) if ( plotTrack )
{ {
for ( RimWellLogCurve* curve : plotTrack->curves() ) for ( RimWellLogCurve* curve : plotTrack->curves() )

View File

@ -234,10 +234,15 @@ size_t RimDepthTrackPlot::plotIndex( const RimPlot* plot ) const
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimPlot* RimDepthTrackPlot::plotByIndex( size_t index ) const RimPlot* RimDepthTrackPlot::plotByIndex( size_t index ) const
{
if ( index < m_plots.size() )
{ {
return m_plots[index]; return m_plots[index];
} }
return nullptr;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -272,14 +272,6 @@ size_t RimMultiPlot::plotIndex( const RimPlot* plot ) const
return m_plots.index( plot ); return m_plots.index( plot );
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlot* RimMultiPlot::plotByIndex( size_t index ) const
{
return m_plots[index];
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -76,7 +76,6 @@ public:
size_t plotCount() const override; size_t plotCount() const override;
size_t plotIndex( const RimPlot* plot ) const; size_t plotIndex( const RimPlot* plot ) const;
RimPlot* plotByIndex( size_t index ) const;
std::vector<RimPlot*> plots() const override; std::vector<RimPlot*> plots() const override;
std::vector<RimPlot*> visiblePlots() const; std::vector<RimPlot*> visiblePlots() const;