diff options
author | Eike Rathke <erack@redhat.com> | 2020-03-27 17:54:09 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2020-03-27 20:04:48 +0100 |
commit | 811b36e4db240be3a21a4d184b085630efcc09b7 (patch) | |
tree | 054ba369e6bbfd13c82186a2c207c20b32263fd4 /sc | |
parent | 45fbfbfeae1de12e87d0a3748e22553b69adbc4a (diff) |
Resolves: tdf#131096 Handle argument error and propagate
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
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/interpr8.cxx | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/sc/source/core/tool/interpr8.cxx b/sc/source/core/tool/interpr8.cxx index 2e15c142290c..1849ab13e6c9 100644 --- a/sc/source/core/tool/interpr8.cxx +++ b/sc/source/core/tool/interpr8.cxx @@ -990,6 +990,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]); @@ -1120,6 +1126,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 ); @@ -1190,7 +1202,7 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType ) nAggregation = 1; if ( nAggregation < 1 || nAggregation > 7 ) { - PushIllegalParameter(); + PushIllegalArgument(); return; } @@ -1204,7 +1216,7 @@ void ScInterpreter::ScForecast_Ets( ScETSType eETSType ) bDataCompletion = nTemp; else { - PushIllegalParameter(); + PushIllegalArgument(); return; } } @@ -1231,16 +1243,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; } } @@ -1258,7 +1270,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; } } @@ -1313,7 +1325,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 : @@ -1325,13 +1340,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 : @@ -1341,13 +1358,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; |