#4395 Robustness : Guard array out of bounds access

This commit is contained in:
Magne Sjaastad 2019-05-06 13:44:40 +02:00
parent 29ec970b02
commit ac8ea73c36
2 changed files with 19 additions and 11 deletions

View File

@ -118,6 +118,8 @@ const std::vector<double>* RigFlowDiagResults::findOrCalculateResult(const RigFl
//--------------------------------------------------------------------------------------------------
void RigFlowDiagResults::calculateNativeResultsIfNotPreviouslyAttempted(size_t timeStepIndex, RigFlowDiagResultAddress::PhaseSelection phaseSelection)
{
if (timeStepIndex >= m_hasAtemptedNativeResults.size()) return;
auto it = m_hasAtemptedNativeResults[timeStepIndex].find(phaseSelection);
if ( it == m_hasAtemptedNativeResults[timeStepIndex].end() || !it->second )
{
@ -701,10 +703,13 @@ double RigFlowDiagResults::maxAbsPairFlux(int timeStepIndex)
calculateNativeResultsIfNotPreviouslyAttempted(timeStepIndex, RigFlowDiagResultAddress::PHASE_ALL);
double maxFlux = 0.0;
for (const auto& commPair : m_injProdPairFluxCommunicationTimesteps[timeStepIndex][RigFlowDiagResultAddress::PHASE_ALL])
if (timeStepIndex < m_injProdPairFluxCommunicationTimesteps.size())
{
if (fabs(commPair.second.first) > maxFlux ) maxFlux = fabs(commPair.second.first);
if (fabs(commPair.second.second) > maxFlux ) maxFlux = fabs(commPair.second.second);
for (const auto& commPair : m_injProdPairFluxCommunicationTimesteps[timeStepIndex][RigFlowDiagResultAddress::PHASE_ALL])
{
if (fabs(commPair.second.first) > maxFlux ) maxFlux = fabs(commPair.second.first);
if (fabs(commPair.second.second) > maxFlux ) maxFlux = fabs(commPair.second.second);
}
}
return maxFlux;

View File

@ -113,20 +113,23 @@ RiuFlowCharacteristicsPlot::~RiuFlowCharacteristicsPlot()
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::setLorenzCurve(const QStringList& dateTimeStrings, const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues)
{
initializeColors(dateTimes);
m_lorenzPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
for (size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx)
if (!dateTimes.empty())
{
if (timeHistoryValues[tsIdx] == HUGE_VAL) continue;
initializeColors(dateTimes);
QDateTime dateTime = dateTimes[tsIdx];
double timeHistoryValue = timeHistoryValues[tsIdx];
for (size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx)
{
if (timeHistoryValues[tsIdx] == HUGE_VAL) continue;
QString curveName = dateTimeStrings[static_cast<int>(tsIdx)];
QDateTime dateTime = dateTimes[tsIdx];
double timeHistoryValue = timeHistoryValues[tsIdx];
RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(m_lorenzPlot, curveName, m_dateToColorMap[dateTime], dateTime, timeHistoryValue);
QString curveName = dateTimeStrings[static_cast<int>(tsIdx)];
RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(m_lorenzPlot, curveName, m_dateToColorMap[dateTime], dateTime, timeHistoryValue);
}
}
m_lorenzPlot->replot();