[Libreoffice-commits] core.git: sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Dec 3 14:27:09 UTC 2018
sc/source/core/opencl/op_financial.cxx | 54 ++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 20 deletions(-)
New commits:
commit 07e15bb76225d259a9be4c7a47b2af0c6cc5b033
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Nov 9 13:52:12 2018 +0100
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Dec 3 15:26:44 2018 +0100
avoid crash in opencl AMORDEGRC and AMORLINT argument handling
The last argument is optional and defaults to 0 according to docs.
Change-Id: I2e3aeb1da13b119e03e5bca18a63447e0fdc77fa
Reviewed-on: https://gerrit.libreoffice.org/64224
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index c276e680f8ba..7504cad66617 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3543,7 +3543,7 @@ void OpAmordegrc::GenSlidingWindowFunction(std::stringstream &ss,
FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
- FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
+ FormulaToken *tmpCur6 = vSubArguments.size() < 7 ? nullptr : vSubArguments[6]->GetFormulaToken();
if(tmpCur0->GetType() == formula::svSingleVectorRef)
{
const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
@@ -3610,17 +3610,24 @@ void OpAmordegrc::GenSlidingWindowFunction(std::stringstream &ss,
ss << " fRate=";
ss << vSubArguments[5]->GenSlidingWindowDeclRef();
ss << ";\n";
- if(tmpCur6->GetType() == formula::svSingleVectorRef)
+ if(tmpCur6 == nullptr)
{
- const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
- formula::SingleVectorRefToken *>(tmpCur6);
- ss <<" if(isnan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
- ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
- ss <<" nBase = 0;\n else\n";
+ ss << " nBase = 0;\n";
+ }
+ else
+ {
+ if(tmpCur6->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR6=
+ static_cast<const formula::SingleVectorRefToken *>(tmpCur6);
+ ss <<" if(isnan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
+ ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
+ ss <<" nBase = 0;\n else\n";
+ }
+ ss << " nBase = (int)";
+ ss << vSubArguments[6]->GenSlidingWindowDeclRef();
+ ss << ";\n";
}
- ss << " nBase = (int)";
- ss << vSubArguments[6]->GenSlidingWindowDeclRef();
- ss << ";\n";
ss <<" uint nPer = convert_int( fPer );\n";
ss <<" double fUsePer = 1.0 *pow( fRate,-1);\n";
ss <<" double fAmorCoeff;\n";
@@ -3691,7 +3698,7 @@ void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss,
FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
- FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
+ FormulaToken *tmpCur6 = vSubArguments.size() < 7 ? nullptr : vSubArguments[6]->GetFormulaToken();
if(tmpCur0->GetType() == formula::svSingleVectorRef)
{
const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
@@ -3758,17 +3765,24 @@ void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss,
ss << " fRate=";
ss << vSubArguments[5]->GenSlidingWindowDeclRef();
ss << ";\n";
- if(tmpCur6->GetType() == formula::svSingleVectorRef)
+ if(tmpCur6 == nullptr)
{
- const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
- formula::SingleVectorRefToken *>(tmpCur6);
- ss <<" if(isnan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
- ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
- ss <<" nBase = 0;\n else\n";
+ ss << " nBase = 0;\n";
+ }
+ else
+ {
+ if(tmpCur6->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR6=
+ static_cast<const formula::SingleVectorRefToken *>(tmpCur6);
+ ss <<" if(isnan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
+ ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
+ ss <<" nBase = 0;\n else\n";
+ }
+ ss << " nBase = (int)";
+ ss << vSubArguments[6]->GenSlidingWindowDeclRef();
+ ss << ";\n";
}
- ss << " nBase = (int)";
- ss << vSubArguments[6]->GenSlidingWindowDeclRef();
- ss << ";\n";
ss <<" int nPer = convert_int( fPer );\n";
ss <<" double fOneRate = fCost * fRate;\n";
ss <<" double fCostDelta = fCost - fRestVal;\n";
More information about the Libreoffice-commits
mailing list