summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2020-03-27 17:54:09 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-03-27 21:59:16 +0100
commitcddb53f5678fde8ad247524561f423b6498b29eb (patch)
tree0b6bee13860e745dd5b39424fab16c6c4a4ea96c
parent748d0fb49c9dcd559ad9e590390bcf1c9005b203 (diff)
Resolves: tdf#131096 Handle argument error and propagatelibreoffice-6-3
For etsPIAdd and etsPIMult also check if the fPILevel parameter was actually specified (explicitly or missing/omitted) and do not pop the 3rd parameter if not. GetDoubleWithDefault() can't handle that as apparently was erroneously assumed. Use IllegalArgument error instead of IllegalParameter in most cases (the parameter is fine but the argument value is not). Actually propagate ScETSForecastCalculation::mnErrorValue if set as PushMatrix() does not, on purpose. Change-Id: Ia2db5b0a7a388f0f40b73c6a4f66debbedec41e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91232 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins (cherry picked from commit 811b36e4db240be3a21a4d184b085630efcc09b7) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91182 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/source/core/tool/interpr8.cxx41
1 files changed, 31 insertions, 10 deletions
diff --git a/sc/source/core/tool/interpr8.cxx b/sc/source/core/tool/interpr8.cxx
index 5e3700ce5cff..0fa198c6ebb6 100644
--- a/sc/source/core/tool/interpr8.cxx
+++ b/sc/source/core/tool/interpr8.cxx
@@ -981,6 +981,12 @@ void ScETSForecastCalculation::GetETSPredictionIntervals( const ScMatrixRef& rTM
if ( fmod( fMaxTarget, mfStepSize ) != 0.0 )
nSize++;
+ if (nSize == 0)
+ {
+ mnErrorValue = FormulaError::IllegalArgument;
+ return;
+ }
+
std::unique_ptr< double[] > xScenRange( new double[nSize]);
std::unique_ptr< double[] > xScenBase( new double[nSize]);
std::unique_ptr< double[] > xScenTrend( new double[nSize]);
@@ -1111,6 +1117,12 @@ void ScETSForecastCalculation::GetEDSPredictionIntervals( const ScMatrixRef& rTM
if ( fmod( fMaxTarget, mfStepSize ) != 0.0 )
nSize++;
+ if (nSize == 0)
+ {
+ mnErrorValue = FormulaError::IllegalArgument;
+ return;
+ }
+
double z = ScInterpreter::gaussinv( ( 1.0 + fPILevel ) / 2.0 );
double o = 1 - fPILevel;
std::vector< double > c( nSize );
@@ -1181,7 +1193,7 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
nAggregation = 1;
if ( nAggregation < 1 || nAggregation > 7 )
{
- PushIllegalParameter();
+ PushIllegalArgument();
return;
}
@@ -1195,7 +1207,7 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
bDataCompletion = nTemp;
else
{
- PushIllegalParameter();
+ PushIllegalArgument();
return;
}
}
@@ -1222,16 +1234,16 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
double fPILevel = 0.0;
if ( nParamCount < 3 && !( nParamCount == 2 && eETSType == etsSeason ) )
{
- PushIllegalArgument();
+ PushParameterExpected();
return;
}
if ( eETSType == etsPIAdd || eETSType == etsPIMult )
{
- fPILevel = GetDoubleWithDefault( 0.95 );
+ fPILevel = (nParamCount < 4 ? 0.95 : GetDoubleWithDefault( 0.95 ));
if ( fPILevel < 0 || fPILevel > 1 )
{
- PushIllegalParameter();
+ PushIllegalArgument();
return;
}
}
@@ -1249,7 +1261,7 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
if ( static_cast< int >( pTypeMat->GetDouble( j, i ) ) < 1 ||
static_cast< int >( pTypeMat->GetDouble( j, i ) ) > 9 )
{
- PushIllegalParameter();
+ PushIllegalArgument();
return;
}
}
@@ -1304,7 +1316,10 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
pTMat->GetDimensions( nC, nR );
ScMatrixRef pFcMat = GetNewMat( nC, nR );
aETSCalc.GetForecastRange( pTMat, pFcMat );
- PushMatrix( pFcMat );
+ if (aETSCalc.GetError() != FormulaError::NONE)
+ PushError( aETSCalc.GetError()); // explicitly push error, PushMatrix() does not
+ else
+ PushMatrix( pFcMat );
}
break;
case etsPIAdd :
@@ -1316,13 +1331,15 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
if ( nSmplInPrd == 0 )
{
aETSCalc.GetEDSPredictionIntervals( pTMat, pPIMat, fPILevel );
- PushMatrix( pPIMat );
}
else
{
aETSCalc.GetETSPredictionIntervals( pTMat, pPIMat, fPILevel );
- PushMatrix( pPIMat );
}
+ if (aETSCalc.GetError() != FormulaError::NONE)
+ PushError( aETSCalc.GetError()); // explicitly push error, PushMatrix() does not
+ else
+ PushMatrix( pPIMat );
}
break;
case etsStatAdd :
@@ -1332,13 +1349,17 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType )
pTypeMat->GetDimensions( nC, nR );
ScMatrixRef pStatMat = GetNewMat( nC, nR );
aETSCalc.GetStatisticValue( pTypeMat, pStatMat );
- PushMatrix( pStatMat );
+ if (aETSCalc.GetError() != FormulaError::NONE)
+ PushError( aETSCalc.GetError()); // explicitly push error, PushMatrix() does not
+ else
+ PushMatrix( pStatMat );
}
break;
case etsSeason :
{
double rVal;
aETSCalc.GetSamplesInPeriod( rVal );
+ SetError( aETSCalc.GetError() );
PushDouble( rVal );
}
break;