mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 23:20:29 -05:00
#14778 Fix crashes from unguarded pointer and index accesses
* Skip deleted plot widgets in RiuMultiPlotBook::visiblePlotWidgets * Guard missing calculation in detectCyclicCalculation * Guard invalid node index in RigFemPart node lookups * Guard null well path in RimWellLogExtractionCurve::extractGeomData * Guard unopened case in RimGridCalculation::removeDependentObjects * Guard empty subset in createLateralAtMeasuredDepth
This commit is contained in:
1 parent
4d2a868079
commit
3437cf9b94
12 files changed
+129
-14
No files matched your search
@@ -162,6 +162,8 @@ set(SOURCE_UNITTEST_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaNameUniquenessTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkSurfaceImporter-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigFemPart-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicNewWellPathLateralAtDepthFeature-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifVtkImportUtil-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaKeyValueStore-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEnsembleImportTools-Test.cpp
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "WellPathCommands/RicNewWellPathLateralAtDepthFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "Well/RigWellPath.h"
|
||||
|
||||
#include "RimModeledWellPath.h"
|
||||
#include "RimWellPath.h"
|
||||
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// A tie-in depth above the start of the parent well path, like the default depth of the Python
|
||||
/// interface, gives an empty subset of the parent well path. The lateral must still be created.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RicNewWellPathLateralAtDepthFeature, TieInDepthAboveStartOfParent )
|
||||
{
|
||||
RimWellPath parentWellPath;
|
||||
|
||||
const std::vector<cvf::Vec3d> points = { { 0.0, 0.0, 0.0 }, { 0.0, 0.0, -100.0 }, { 0.0, 0.0, -200.0 } };
|
||||
const std::vector<double> measuredDepths = { 100.0, 200.0, 300.0 };
|
||||
|
||||
auto* geometry = new RigWellPath;
|
||||
geometry->setWellPathPoints( points, measuredDepths );
|
||||
parentWellPath.setWellPathGeometry( geometry );
|
||||
|
||||
RimModeledWellPath* lateral = RicNewWellPathLateralAtDepthFeature::createLateralAtMeasuredDepth( &parentWellPath, 0.0 );
|
||||
EXPECT_TRUE( lateral != nullptr );
|
||||
|
||||
RiaApplication::instance()->closeProject();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RigFemPart.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// A part with elements but no nodes, as read from a malformed model, gives connectivities that are
|
||||
/// outside the node list. Calculating neighbors must not read outside the node to element references.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RigFemPart, ElmNeighbors_ElementsWithoutNodes )
|
||||
{
|
||||
RigFemPart part;
|
||||
|
||||
const int connectivities[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
part.preAllocateElementStorage( 1 );
|
||||
part.appendElement( RigElementType::HEX8, 1, connectivities );
|
||||
|
||||
part.assertNodeToElmIndicesIsCalculated();
|
||||
part.assertElmNeighborsIsCalculated();
|
||||
|
||||
EXPECT_TRUE( part.elementsUsingNode( 0 ).empty() );
|
||||
EXPECT_TRUE( part.elementsUsingNode( -1 ).empty() );
|
||||
EXPECT_TRUE( part.elementLocalIndicesForNode( 0 ).empty() );
|
||||
EXPECT_TRUE( part.elementLocalIndicesForNode( -1 ).empty() );
|
||||
}
|
||||
@@ -116,3 +116,25 @@ TEST( RimGridCalculationTest, AdditionalEnsembleCasesAreOutputs )
|
||||
EXPECT_EQ( firstCase, outputCases[0] );
|
||||
EXPECT_EQ( secondCase, outputCases[1] );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// The results of a case that is not opened are not available, and must not be accessed when the calculation is removed
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RimGridCalculationTest, RemoveDependentObjectsForCaseNotOpened )
|
||||
{
|
||||
RimReservoirGridEnsemble ensemble;
|
||||
auto* notOpenedCase = new RimEclipseResultCase;
|
||||
ensemble.addCase( notOpenedCase );
|
||||
|
||||
RimGridCalculation calculation;
|
||||
calculation.setExpression( "MY_CALCULATION := 1" );
|
||||
|
||||
auto* destinationEnsembleField =
|
||||
dynamic_cast<caf::PdmPtrField<RimReservoirGridEnsemble*>*>( calculation.findField( "DestinationEnsemble" ) );
|
||||
ASSERT_TRUE( destinationEnsembleField != nullptr );
|
||||
destinationEnsembleField->setValue( &ensemble );
|
||||
|
||||
ASSERT_TRUE( notOpenedCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ) == nullptr );
|
||||
|
||||
calculation.removeDependentObjects();
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifEclipseSummaryAddressDefines.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCalculation.h"
|
||||
|
||||
using SummaryCategory = RifEclipseSummaryAddressDefines::SummaryCategory;
|
||||
@@ -28,6 +29,8 @@ public:
|
||||
{
|
||||
return singleAddressesForCategory( address );
|
||||
}
|
||||
|
||||
bool testDetectCyclicCalculation( int id, std::set<int>& ids ) const { return detectCyclicCalculation( id, ids ); }
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -217,3 +220,15 @@ TEST( RimSummaryCalculation, SubstituteVariables_BlockLgr )
|
||||
EXPECT_EQ( 20, vars[0].summaryAddress.cellJ() );
|
||||
EXPECT_EQ( 30, vars[0].summaryAddress.cellK() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// A calculation referring to a calculation that is already removed from the collection, as when the
|
||||
/// referenced calculation is being deleted, is not cyclic
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RimSummaryCalculation, DetectCyclicCalculation_MissingCalculation )
|
||||
{
|
||||
RimSummaryCalculationTester calculation;
|
||||
|
||||
std::set<int> ids;
|
||||
EXPECT_FALSE( calculation.testDetectCyclicCalculation( 9999, ids ) );
|
||||
}
|
||||
Reference in new issue
Block a user