CppCheck : Several fixes

Add missing initializers
Guard potential null pointer access
This commit is contained in:
Magne Sjaastad
2018-08-02 19:22:03 +02:00
parent 39c4319fa4
commit fe07b60392
21 changed files with 184 additions and 148 deletions

View File

@@ -81,20 +81,22 @@ void RicExportFaultsFeature::onActionTriggered(bool isChecked)
RimEclipseCase* eclCase = nullptr;
rimFault->firstAncestorOrThisOfType(eclCase);
QString caseName;
if (eclCase)
{
QString caseName = eclCase->caseUserDescription();
if (eclCase) caseName = eclCase->caseUserDescription();
QString faultName = rimFault->name();
if (faultName == RiaDefines::undefinedGridFaultName()) faultName = "UNDEF";
if (faultName == RiaDefines::undefinedGridFaultWithInactiveName()) faultName = "UNDEF_IA";
QString faultName = rimFault->name();
if ( faultName == RiaDefines::undefinedGridFaultName() ) faultName = "UNDEF";
if ( faultName == RiaDefines::undefinedGridFaultWithInactiveName() ) faultName = "UNDEF_IA";
QString baseFilename = "Fault_" + faultName + "_" + caseName;
baseFilename = caf::Utils::makeValidFileBasename(baseFilename);
QString baseFilename = "Fault_" + faultName + "_" + caseName;
baseFilename = caf::Utils::makeValidFileBasename(baseFilename);
QString completeFilename = selectedDir + "/" + baseFilename + ".grdecl";
QString completeFilename = selectedDir + "/" + baseFilename + ".grdecl";
RicExportFaultsFeature::saveFault(completeFilename, eclCase->eclipseCaseData()->mainGrid(), rimFault->faultGeometry()->faultFaces(), faultName);
RicExportFaultsFeature::saveFault(
completeFilename, eclCase->eclipseCaseData()->mainGrid(), rimFault->faultGeometry()->faultFaces(), faultName);
}
}

View File

@@ -136,9 +136,10 @@ QImage RicGridStatisticsDialog::screenShotImage()
//--------------------------------------------------------------------------------------------------
void RicGridStatisticsDialog::setInfoText(RimGridView* view)
{
Rim3dOverlayInfoConfig* overlayInfo = view->overlayInfoConfig();
if (view && overlayInfo)
if (view && view->overlayInfoConfig())
{
Rim3dOverlayInfoConfig* overlayInfo = view->overlayInfoConfig();
QString text;
text = overlayInfo->timeStepText();
text += overlayInfo->caseInfoText();
@@ -156,9 +157,10 @@ void RicGridStatisticsDialog::setHistogramData(RimGridView* view)
deletePlotItems(m_historgramPlot);
deletePlotItems(m_aggregatedPlot);
Rim3dOverlayInfoConfig* overlayInfo = view->overlayInfoConfig();
if (view && overlayInfo)
if (view && view->overlayInfoConfig())
{
Rim3dOverlayInfoConfig* overlayInfo = view->overlayInfoConfig();
auto hist = new QwtPlotHistogram("Histogram");
auto aggr = new QwtPlotCurve("Aggregated");

View File

@@ -36,6 +36,7 @@
///
//--------------------------------------------------------------------------------------------------
RicSummaryCurveCalculatorEditor::RicSummaryCurveCalculatorEditor()
: m_pdmTableView(nullptr)
{
m_calculator = std::unique_ptr<RicSummaryCurveCalculator>(new RicSummaryCurveCalculator);

View File

@@ -60,7 +60,7 @@ void RicWellLogFileCloseFeature::onActionTriggered(bool isChecked)
RimWellPath* parentWellPath;
wellLogFile->firstAncestorOrThisOfType(parentWellPath);
if (parentWellPath != nullptr)
if (parentWellPath)
{
std::set<RimViewWindow*> referringPlots = referringWellLogPlots(wellLogFile);
parentWellPath->deleteWellLogFile(wellLogFile);
@@ -69,8 +69,9 @@ void RicWellLogFileCloseFeature::onActionTriggered(bool isChecked)
{
plot->loadDataAndUpdate();
}
parentWellPath->updateConnectedEditors();
}
parentWellPath->updateConnectedEditors();
}
caf::PdmUiObjectEditorHandle::updateUiAllObjectEditors();

View File

@@ -63,40 +63,45 @@ bool RicWellPathViewerEventHandler::handleEvent(const RicViewerEventObject& even
{
const auto & partAndTriangleIndexPair = eventObject.m_partAndTriangleIndexPairs.front();
const cvf::Part* part = partAndTriangleIndexPair.first;
const RivObjectSourceInfo* sourceInfo = dynamic_cast<const RivObjectSourceInfo*>(part->sourceInfo());
if (sourceInfo)
{
if (dynamic_cast<RimPerforationInterval*>(sourceInfo->object()))
{
objectToSelect = sourceInfo->object();
if (eventObject.m_partAndTriangleIndexPairs.size() > 1)
if (part)
{
const RivObjectSourceInfo* sourceInfo = dynamic_cast<const RivObjectSourceInfo*>(part->sourceInfo());
if (sourceInfo)
{
if (dynamic_cast<RimPerforationInterval*>(sourceInfo->object()))
{
const auto& secondPair = eventObject.m_partAndTriangleIndexPairs[1];
const cvf::Part* secondPickedPart = secondPair.first;
if (secondPickedPart)
objectToSelect = sourceInfo->object();
if (eventObject.m_partAndTriangleIndexPairs.size() > 1)
{
auto wellPathSourceCandidate = dynamic_cast<const RivWellPathSourceInfo*>(secondPickedPart->sourceInfo());
if (wellPathSourceCandidate)
const auto& secondPair = eventObject.m_partAndTriangleIndexPairs[1];
const cvf::Part* secondPickedPart = secondPair.first;
if (secondPickedPart)
{
RimWellPath* perforationWellPath = nullptr;
objectToSelect->firstAncestorOrThisOfType(perforationWellPath);
if (perforationWellPath == wellPathSourceCandidate->wellPath())
auto wellPathSourceCandidate =
dynamic_cast<const RivWellPathSourceInfo*>(secondPickedPart->sourceInfo());
if (wellPathSourceCandidate)
{
wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(secondPickedPart->sourceInfo());
wellPathTriangleIndex = secondPair.second;
RimWellPath* perforationWellPath = nullptr;
objectToSelect->firstAncestorOrThisOfType(perforationWellPath);
if (perforationWellPath == wellPathSourceCandidate->wellPath())
{
wellPathSourceInfo =
dynamic_cast<const RivWellPathSourceInfo*>(secondPickedPart->sourceInfo());
wellPathTriangleIndex = secondPair.second;
}
}
}
}
}
}
}
if (part && dynamic_cast<const RivWellPathSourceInfo*>(part->sourceInfo()))
{
wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(part->sourceInfo());
wellPathTriangleIndex = partAndTriangleIndexPair.second;
if (dynamic_cast<const RivWellPathSourceInfo*>(part->sourceInfo()))
{
wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(part->sourceInfo());
wellPathTriangleIndex = partAndTriangleIndexPair.second;
}
}
}

View File

@@ -72,6 +72,7 @@ RifSummaryCaseRestartSelector::RifSummaryCaseRestartSelector()
m_showDialog = prefs->summaryRestartFilesShowImportDialog();
m_defaultSummaryImportMode = mapReadOption(prefs->summaryImportMode());
m_defaultGridImportMode = mapReadOption(prefs->gridImportMode());
m_ensembleOrGroupMode = false;
//m_buildGridFileList = false;
m_gridFiles.clear();

View File

@@ -30,22 +30,24 @@ class RigFemResultAddress
{
public:
RigFemResultAddress()
: resultPosType(RIG_NODAL)
, fieldName("")
, componentName("")
, timeLapseBaseFrameIdx(NO_TIME_LAPSE)
, refKLayerIndex(NO_COMPACTION)
{
resultPosType = RIG_NODAL;
fieldName = "";
componentName = "";
}
RigFemResultAddress(RigFemResultPosEnum resPosType,
const std::string& aFieldName,
const std::string& aComponentName,
int timeLapseBaseFrameIdx = NO_TIME_LAPSE,
int refKLayerIndex = NO_COMPACTION)
: resultPosType(resPosType),
fieldName(aFieldName),
componentName(aComponentName),
timeLapseBaseFrameIdx(timeLapseBaseFrameIdx),
refKLayerIndex(refKLayerIndex)
const std::string& aFieldName,
const std::string& aComponentName,
int timeLapseBaseFrameIdx = NO_TIME_LAPSE,
int refKLayerIndex = NO_COMPACTION)
: resultPosType(resPosType)
, fieldName(aFieldName)
, componentName(aComponentName)
, timeLapseBaseFrameIdx(timeLapseBaseFrameIdx)
, refKLayerIndex(refKLayerIndex)
{
}

View File

@@ -229,30 +229,35 @@ const QString RivWellFracturePartMgr::resultInfoText(const RimEclipseView& activ
}
else if (stimPlanTemplate)
{
const RigFractureCell* cell = getFractureCellAtDomainCoord(domainIntersectionPoint);
RimStimPlanColors* stimPlanColors = activeView.fractureColors();
const RigFractureCell* cell = getFractureCellAtDomainCoord(domainIntersectionPoint);
if (cell)
{
QString resultNameFromColors = activeView.fractureColors()->uiResultName();
QString resultUnitFromColors = activeView.fractureColors()->unit();
QString resultNameFromColors = activeView.fractureColors()->uiResultName();
QString resultUnitFromColors = activeView.fractureColors()->unit();
double resultValue = stimPlanTemplate->resultValueAtIJ(
resultNameFromColors, resultUnitFromColors, stimPlanTemplate->activeTimeStepIndex(), cell->getI(), cell->getJ());
double resultValue = stimPlanTemplate->resultValueAtIJ(
resultNameFromColors, resultUnitFromColors, stimPlanTemplate->activeTimeStepIndex(), cell->getI(), cell->getJ());
QString resultValueText = QString("%1").arg(resultValue);
QString resultValueText = QString("%1").arg(resultValue);
QString iText = QString::number(cell->getI());
QString jText = QString::number(cell->getJ());
QString iText = cell ? QString::number(cell->getI()) : "-";
QString jText = cell ? QString::number(cell->getJ()) : "-";
RimStimPlanColors* stimPlanColors = activeView.fractureColors();
if (stimPlanColors)
{
// Conductivity
text.append("Result value: ");
// Conductivity
text.append("Result value: ");
QString resultName = stimPlanTemplate->mapUiResultNameToFileResultName(stimPlanColors->uiResultName());
text.append(resultName + " ");
text.append(resultValueText + "\n");
}
QString resultName = stimPlanTemplate->mapUiResultNameToFileResultName(stimPlanColors->uiResultName());
text.append(resultName + " ");
text.append(resultValueText + "\n");
// Cell index
text.append("Cell Index: ");
text.append(iText + ", " + jText + "\n");
// Cell index
text.append("Cell Index: ");
text.append(iText + ", " + jText + "\n");
}
}
return text;

View File

@@ -221,7 +221,7 @@ std::set<size_t> RimFractureContainmentTools::fracturedCellsTruncatedByFaults(co
// Negative faultThrow disables test on faultThrow
double maximumFaultThrow = -1.0;
if (fracture && fracture->fractureTemplate())
if (fracture->fractureTemplate() && fracture->fractureTemplate()->fractureContainment())
{
maximumFaultThrow = fracture->fractureTemplate()->fractureContainment()->minimumFaultThrow();
}

View File

@@ -90,6 +90,7 @@ RimWellLogFile::RimWellLogFile()
m_invalidDateMessage.xmlCapability()->disableIO();
m_wellLogDataFile = nullptr;
m_lasFileHasValidDate = false;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -51,6 +51,8 @@ RimDerivedEnsembleCase::RimDerivedEnsembleCase() : m_summaryCase1(nullptr), m_su
CAF_PDM_InitObject("Summary Case",":/SummaryCase16x16.png","","");
CAF_PDM_InitFieldNoDefault(&m_summaryCase1, "SummaryCase1", "SummaryCase1", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_summaryCase2, "SummaryCase2", "SummaryCase2", "", "", "");
m_inUse = false;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -71,7 +71,5 @@ private:
caf::PdmField<bool> m_showCurveLabels;
caf::PdmField<cvf::Color3f> m_color;
RimSummaryCaseCollection* m_ensemble;
};

View File

@@ -148,17 +148,14 @@ QString RimSummaryCurveAutoName::curveNameX(const RifEclipseSummaryAddress& summ
if (summaryCurve && summaryCurve->summaryCaseX())
{
QString caseName = summaryCurve->summaryCaseX()->caseName();
bool skipSubString = nameHelper && nameHelper->isCaseInTitle();
if (m_caseName && !skipSubString)
{
if (summaryCurve && summaryCurve->summaryCaseX())
{
if (!text.empty()) text += ", ";
text += caseName.toStdString();
}
QString caseName = summaryCurve->summaryCaseX()->caseName();
if (!text.empty()) text += ", ";
text += caseName.toStdString();
}
}

View File

@@ -23,7 +23,14 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigCompletionDataGridCell::RigCompletionDataGridCell() {}
RigCompletionDataGridCell::RigCompletionDataGridCell()
: m_globalCellIndex(0)
, m_lgrName("")
, m_localCellIndexI(0)
, m_localCellIndexJ(0)
, m_localCellIndexK(0)
{
}
//--------------------------------------------------------------------------------------------------
///
@@ -33,9 +40,9 @@ RigCompletionDataGridCell::RigCompletionDataGridCell(size_t globalCellIndex, con
{
if (mainGrid)
{
size_t gridLocalCellIndex;
size_t gridLocalCellIndex;
const RigGridBase* grid = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(globalCellIndex, &gridLocalCellIndex);
if (grid)
{
size_t i = 0;

View File

@@ -20,6 +20,8 @@
#include "RigCaseCellResultsData.h"
#include "RiaLogging.h"
#include "RigEclipseCaseData.h"
#include "RigEclipseMultiPropertyStatCalc.h"
#include "RigEclipseNativeStatCalc.h"
@@ -2320,12 +2322,16 @@ void RigCaseCellResultsData::computeMobilePV()
const std::vector<double>* swcrResults = nullptr;
const std::vector<double>* multpvResults = nullptr;
porvResults = RigCaseCellResultsData::getResultIndexableStaticResult(this->activeCellInfo(), this, "PORV", porvDataTemp);
porvResults = RigCaseCellResultsData::getResultIndexableStaticResult(this->activeCellInfo(), this, "PORV", porvDataTemp);
if (!porvResults || porvResults->empty())
{
RiaLogging::error("Assumed PORV, but not data was found.");
return;
}
swcrResults = RigCaseCellResultsData::getResultIndexableStaticResult(this->activeCellInfo(), this, "SWCR", swcrDataTemp);
multpvResults = RigCaseCellResultsData::getResultIndexableStaticResult(this->activeCellInfo(), this, "MULTPV", multpvDataTemp);
CVF_ASSERT(!porvResults->empty());
size_t mobPVIdx = this->findOrCreateScalarResultIndex(RiaDefines::STATIC_NATIVE, RiaDefines::mobilePoreVolumeName(), false);
std::vector<double> &mobPVResults = this->cellScalarResults(mobPVIdx)[0];
@@ -2333,18 +2339,21 @@ void RigCaseCellResultsData::computeMobilePV()
// Set up output container to correct number of results
mobPVResults.resize(porvResults->size());
if (!(multpvResults || swcrResults))
if (multpvResults && swcrResults)
{
mobPVResults.assign(porvResults->begin(), porvResults->end());
for (size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx)
{
mobPVResults[vIdx] = (*multpvResults)[vIdx] * (*porvResults)[vIdx] * (1.0 - (*swcrResults)[vIdx]);
}
}
else if (!multpvResults)
else if (!multpvResults && swcrResults)
{
for (size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx)
{
mobPVResults[vIdx] = (*porvResults)[vIdx] * (1.0 - (*swcrResults)[vIdx]);
}
}
else if (!swcrResults)
else if (!swcrResults && multpvResults)
{
for (size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx)
{
@@ -2353,10 +2362,7 @@ void RigCaseCellResultsData::computeMobilePV()
}
else
{
for (size_t vIdx = 0; vIdx < porvResults->size(); ++vIdx)
{
mobPVResults[vIdx] = (*multpvResults)[vIdx] * (*porvResults)[vIdx] * (1.0 - (*swcrResults)[vIdx]);
}
mobPVResults.assign(porvResults->begin(), porvResults->end());
}
}

View File

@@ -511,15 +511,16 @@ bool RigFlowDiagSolverInterface::ensureStaticDataObjectInstanceCreated()
if (initFileName.empty()) return false;
const RigEclipseCaseData* eclipseCaseData = m_eclipseCase->eclipseCaseData();
if (eclipseCaseData->hasFractureResults())
if (eclipseCaseData)
{
return false;
}
if (eclipseCaseData->hasFractureResults())
{
return false;
}
RiaEclipseUnitTools::UnitSystem caseUnitSystem = eclipseCaseData ? eclipseCaseData->unitsType() : RiaEclipseUnitTools::UNITS_UNKNOWN;
m_opmFlowDiagStaticData = new RigOpmFlowDiagStaticData(gridFileName.toStdString(), initFileName, caseUnitSystem);
RiaEclipseUnitTools::UnitSystem caseUnitSystem = eclipseCaseData->unitsType();
m_opmFlowDiagStaticData = new RigOpmFlowDiagStaticData(gridFileName.toStdString(), initFileName, caseUnitSystem);
}
}
return m_opmFlowDiagStaticData.notNull() ? true : false;

View File

@@ -66,11 +66,6 @@ cvf::ref<RigResultAccessor> RigResultAccessorFactory::createFromNameAndType(cons
const QString& uiResultName,
RiaDefines::ResultCatType resultType)
{
CVF_ASSERT(gridIndex < eclipseCase->gridCount());
CVF_ASSERT(eclipseCase);
CVF_ASSERT(eclipseCase->results(porosityModel));
CVF_ASSERT(eclipseCase->activeCellInfo(porosityModel));
if (!eclipseCase || !eclipseCase->results(porosityModel) || !eclipseCase->activeCellInfo(porosityModel))
{
return nullptr;
@@ -148,11 +143,6 @@ cvf::ref<RigResultAccessor> RigResultAccessorFactory::createNativeFromUiResultNa
size_t timeStepIndex,
const QString& uiResultName)
{
CVF_ASSERT(gridIndex < eclipseCase->gridCount());
CVF_ASSERT(eclipseCase);
CVF_ASSERT(eclipseCase->results(porosityModel));
CVF_ASSERT(eclipseCase->activeCellInfo(porosityModel));
if (!eclipseCase || !eclipseCase->results(porosityModel) || !eclipseCase->activeCellInfo(porosityModel))
{
return nullptr;

View File

@@ -42,10 +42,13 @@ size_t findMirrorXIndex(std::vector<double> xs);
const double RigStimPlanFractureDefinition::THRESHOLD_VALUE = 1e-5;
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RigStimPlanFractureDefinition::RigStimPlanFractureDefinition() :
m_unitSet(RiaEclipseUnitTools::UNITS_UNKNOWN), m_topPerfTvd(HUGE_VAL), m_bottomPerfTvd(HUGE_VAL)
RigStimPlanFractureDefinition::RigStimPlanFractureDefinition()
: m_unitSet(RiaEclipseUnitTools::UNITS_UNKNOWN)
, m_topPerfTvd(HUGE_VAL)
, m_bottomPerfTvd(HUGE_VAL)
, m_xMirrorMode(false)
{
}

View File

@@ -77,33 +77,33 @@ RimMdiWindowGeometry RiuMdiSubWindow::windowGeometryForWidget(QWidget* widget)
{
RimMdiWindowGeometry geo;
// Find topmost parent
QWidget* nextParent = widget->parentWidget();
QWidget* parent = nullptr;
while(nextParent)
{
parent = nextParent;
nextParent = nextParent->parentWidget();
}
int mainWinID = 0;
if (parent)
{
if (parent == RiaApplication::instance()->mainPlotWindow())
{
mainWinID = 1;
}
}
if (widget)
{
// Find topmost parent
QWidget* nextParent = widget->parentWidget();
QWidget* parent = nullptr;
while (nextParent)
{
parent = nextParent;
nextParent = nextParent->parentWidget();
}
int mainWinID = 0;
if (parent)
{
if (parent == RiaApplication::instance()->mainPlotWindow())
{
mainWinID = 1;
}
}
geo.mainWindowID = mainWinID;
geo.x = widget->pos().x();
geo.y = widget->pos().y();
geo.width = widget->size().width();
geo.height = widget->size().height();
geo.isMaximized = widget->isMaximized();
geo.x = widget->pos().x();
geo.y = widget->pos().y();
geo.width = widget->size().width();
geo.height = widget->size().height();
geo.isMaximized = widget->isMaximized();
}
return geo;

View File

@@ -325,9 +325,18 @@ void RiuSelectionChangedHandler::updateResultInfo(const RiuSelectionItem* itemAd
if (selItem->type() == RiuSelectionItem::INTERSECTION_SELECTION_OBJECT)
{
const Riu2dIntersectionSelectionItem* wrapperSelItem = dynamic_cast<Riu2dIntersectionSelectionItem*>(selItem);
intersectionView = wrapperSelItem->view();
if (wrapperSelItem && wrapperSelItem->eclipseSelectionItem()) selItem = wrapperSelItem->eclipseSelectionItem();
else if (wrapperSelItem && wrapperSelItem->geoMechSelectionItem()) selItem = wrapperSelItem->geoMechSelectionItem();
if (wrapperSelItem)
{
intersectionView = wrapperSelItem->view();
if (wrapperSelItem->eclipseSelectionItem())
{
selItem = wrapperSelItem->eclipseSelectionItem();
}
else if (wrapperSelItem->geoMechSelectionItem())
{
selItem = wrapperSelItem->geoMechSelectionItem();
}
}
}
if (selItem->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT)

View File

@@ -491,23 +491,26 @@ void RiuSummaryQwtPlot::selectClosestCurve(const QPoint& pos)
}
}
if(closestCurve && distMin < 20)
if (closestCurve && distMin < 20)
{
caf::PdmObject* selectedPlotObject = m_plotDefinition->findRimPlotObjectFromQwtCurve(closestCurve);
RimProject* proj = nullptr;
selectedPlotObject->firstAncestorOrThisOfType(proj);
if(proj && selectedPlotObject)
if (selectedPlotObject)
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem(selectedPlotObject);
RimProject* proj = nullptr;
selectedPlotObject->firstAncestorOrThisOfType(proj);
if (proj)
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem(selectedPlotObject);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::onZoomedSlot()
{