sc/source/core/opencl/op_financial.cxx   |   18 ++++++++++++++++++
 sc/source/core/opencl/op_math.cxx        |   25 +++++++++++++++++++++++++
 sc/source/core/opencl/op_statistical.cxx |    2 ++
 3 files changed, 45 insertions(+)

New commits:
commit 256086fc9b3a00181c7022294712226cd920b2e1
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Wed Aug 31 16:43:37 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Thu Sep 1 12:21:53 2022 +0200

    check parameter count in various opencl functions
    
    Change-Id: I896331287ac5f7705f9fdfdb8e0786a894bc6eb9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139077
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/opencl/op_financial.cxx 
b/sc/source/core/opencl/op_financial.cxx
index e3362ed08441..12acbb435081 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -21,6 +21,7 @@ namespace sc::opencl {
 void RRI::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 3, 3 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -148,6 +149,7 @@ vSubArguments)
 void OpDollarde::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -512,6 +514,7 @@ void OpIPMT::GenSlidingWindowFunction(outputstream& ss,
 void OpISPMT::GenSlidingWindowFunction(outputstream& ss,
     const std::string &sSymName, SubArguments& vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 4, 4 );
     ss << "\ndouble " << sSymName;
     ss << "_" << BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -796,6 +799,7 @@ void Cumipmt::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &
 vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 6 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -910,6 +914,7 @@ vSubArguments)
 void IRR::GenSlidingWindowFunction(outputstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_" << BinFuncName() << "(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1181,6 +1186,7 @@ void XNPV::GenSlidingWindowFunction(
 void PriceMat::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 6 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1375,6 +1381,7 @@ void OpSYD::GenSlidingWindowFunction(outputstream &ss,
 void MIRR::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 3, 3 );
     FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
     assert(pCur);
     const formula::DoubleVectorRefToken* pCurDVR =
@@ -1591,6 +1598,7 @@ void OpCumprinc::BinInlineFun(std::set<std::string>& 
decls,
 void OpCumprinc::GenSlidingWindowFunction(outputstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 6 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1717,6 +1725,7 @@ void OpAccrint::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName,
     SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 7, 7 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1831,6 +1840,7 @@ void OpAccrintm::BinInlineFun(std::set<std::string>& 
decls,
 void OpAccrintm::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 5, 5 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1958,6 +1968,7 @@ void OpAccrintm::GenSlidingWindowFunction(
 void OpYield::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 7, 7 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2174,6 +2185,7 @@ void OpSLN::GenSlidingWindowFunction(outputstream &ss,
 void OpYieldmat::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 6 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -3525,6 +3537,7 @@ void OpAmordegrc::BinInlineFun(std::set<std::string>& 
decls,
 void OpAmordegrc::GenSlidingWindowFunction(outputstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 7 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -3680,6 +3693,7 @@ void OpAmorlinc::BinInlineFun(std::set<std::string>& 
decls,
 void OpAmorlinc::GenSlidingWindowFunction(outputstream &ss,
              const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 7 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -3818,6 +3832,7 @@ void OpReceived::BinInlineFun(std::set<std::string>& 
decls,
 void OpReceived::GenSlidingWindowFunction(outputstream &ss,
         const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 5, 5 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -4071,6 +4086,7 @@ void OpTbillprice::GenSlidingWindowFunction(
 void RATE::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 6, 6 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -4285,6 +4301,7 @@ void OpTbillyield::GenSlidingWindowFunction(
 void OpDDB::GenSlidingWindowFunction(outputstream& ss,
             const std::string &sSymName, SubArguments& vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 5, 5 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -4682,6 +4699,7 @@ void OpXirr::GenSlidingWindowFunction(outputstream &ss,
 void OpDB::GenSlidingWindowFunction(outputstream& ss,
             const std::string &sSymName, SubArguments& vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 5, 5 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
diff --git a/sc/source/core/opencl/op_math.cxx 
b/sc/source/core/opencl/op_math.cxx
index b6351f77d154..dd70241c5f41 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -300,6 +300,7 @@ void OpCombinA::BinInlineFun(std::set<std::string>& decls,
 void OpCombinA::GenSlidingWindowFunction(outputstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1654,6 +1655,7 @@ void OpRound::GenSlidingWindowFunction(outputstream &ss,
 void OpRoundUp::GenSlidingWindowFunction(outputstream &ss,
              const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 1, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1670,6 +1672,8 @@ void OpRoundUp::GenSlidingWindowFunction(outputstream &ss,
     ss << "    double tmp;\n";
     GenTmpVariables(ss,vSubArguments);
     CheckAllSubArgumentIsNan(ss,vSubArguments);
+    if( vSubArguments.size() == 1 )
+        ss << "    double tmp1 = 0;\n";
     ss << "    if(tmp1 >20 || tmp1 < -20)";
     ss << "    {\n";
     ss << "        tmp = NAN;\n";
@@ -1692,6 +1696,7 @@ void OpRoundUp::GenSlidingWindowFunction(outputstream &ss,
 void OpRoundDown::GenSlidingWindowFunction(outputstream &ss,
              const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 1, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1707,6 +1712,8 @@ void OpRoundDown::GenSlidingWindowFunction(outputstream 
&ss,
     ss << "    double tmp;\n";
     GenTmpVariables(ss,vSubArguments);
     CheckAllSubArgumentIsNan(ss,vSubArguments);
+    if( vSubArguments.size() == 1 )
+        ss << "    double tmp1 = 0;\n";
     ss << "    if(tmp1 >20 || tmp1 < -20)";
     ss << "    {\n";
     ss << "        tmp = NAN;\n";
@@ -2172,6 +2179,7 @@ void OpFloor::GenSlidingWindowFunction(
     outputstream &ss, const std::string &sSymName,
     SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 3 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2516,6 +2524,7 @@ void OpSqrtPi::GenSlidingWindowFunction(outputstream &ss,
 void OpCeil::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 3 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2575,6 +2584,7 @@ void OpCeil::GenSlidingWindowFunction(outputstream &ss,
 void OpCombin::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
diff --git a/sc/source/core/opencl/op_statistical.cxx 
b/sc/source/core/opencl/op_statistical.cxx
index 1225306b69fb..5acd3c2508fc 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -465,6 +465,7 @@ void OpTTest::BinInlineFun(std::set<std::string>& decls,
 void OpTTest::GenSlidingWindowFunction(outputstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 4, 4 );
     ss << "\ndouble " << sSymName;
     ss << "_" << BinFuncName() << "(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1395,6 +1396,7 @@ void OpStandard::GenSlidingWindowFunction(outputstream 
&ss,
 void OpWeibull::GenSlidingWindowFunction(outputstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 4, 4 );
     ss << "\ndouble " << sSymName;
     ss << "_" << BinFuncName() << "(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
commit 0f44a1c0448b0f5ba53167b20c5bf94f92e071d1
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Wed Aug 31 16:43:33 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Thu Sep 1 12:21:37 2022 +0200

    error checking in opencl BIT* functions
    
    Change-Id: Icf76d5d656226de8f96caf59be1d64cf13d07bbe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139076
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/opencl/op_math.cxx 
b/sc/source/core/opencl/op_math.cxx
index 2cb75d5c3d58..b6351f77d154 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -1558,6 +1558,7 @@ void OpArcTanH::GenSlidingWindowFunction(outputstream &ss,
 void OpBitAnd::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -1587,6 +1588,8 @@ void OpBitAnd::GenSlidingWindowFunction(outputstream &ss,
     ss << "        num2 = 0.0;\n";
     ss << "    else \n    ";
     ss << "    num2 = " << vSubArguments[1]->GenSlidingWindowDeclRef() << 
";\n";
+    ss << "    if( num1 < 0 || num2 < 0 || num1 >= 281474976710656.0 || num2 
>= 281474976710656.0 )\n";
+    ss << "        return CreateDoubleError(IllegalArgument);\n";
     ss << "    return (long)num1 & (long)num2;\n";
     ss << "}";
 }
@@ -2204,6 +2207,7 @@ void OpFloor::GenSlidingWindowFunction(
 void OpBitOr::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2235,12 +2239,15 @@ void OpBitOr::GenSlidingWindowFunction(outputstream &ss,
     ss << "    else\n    ";
     ss << "    num2 = floor(" << vSubArguments[1]->GenSlidingWindowDeclRef();
     ss << ");\n";
+    ss << "    if( num1 < 0 || num2 < 0 || num1 >= 281474976710656.0 || num2 
>= 281474976710656.0 )\n";
+    ss << "        return CreateDoubleError(IllegalArgument);\n";
     ss << "    return (long)num1 | (long)num2;\n";
     ss << "}";
 }
 void OpBitXor::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2273,12 +2280,15 @@ void OpBitXor::GenSlidingWindowFunction(outputstream 
&ss,
     ss << "    else\n    ";
     ss << "    num2 = floor(" << vSubArguments[1]->GenSlidingWindowDeclRef();
     ss << ");\n";
+    ss << "    if( num1 < 0 || num2 < 0 || num1 >= 281474976710656.0 || num2 
>= 281474976710656.0 )\n";
+    ss << "        return CreateDoubleError(IllegalArgument);\n";
     ss << "    return (long)num1 ^ (long)num2;\n";
     ss << "}";
 }
 void OpBitLshift::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2311,6 +2321,8 @@ void OpBitLshift::GenSlidingWindowFunction(outputstream 
&ss,
     ss << "    else\n    ";
     ss << "    shift_amount = floor(";
     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
+    ss << "    if( num < 0 || num >= 281474976710656.0 )\n";
+    ss << "        return CreateDoubleError(IllegalArgument);\n";
     ss << "    return floor(shift_amount >= 0 ? ";
     ss << "num * pow(2.0, shift_amount) : ";
     ss << "num / pow(2.0, fabs(shift_amount)));\n";
@@ -2319,6 +2331,7 @@ void OpBitLshift::GenSlidingWindowFunction(outputstream 
&ss,
 void OpBitRshift::GenSlidingWindowFunction(outputstream &ss,
     const std::string &sSymName, SubArguments &vSubArguments)
 {
+    CHECK_PARAMETER_COUNT( 2, 2 );
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (size_t i = 0; i < vSubArguments.size(); i++)
@@ -2353,6 +2366,8 @@ void OpBitRshift::GenSlidingWindowFunction(outputstream 
&ss,
     ss << "    else\n    ";
     ss << "    shift_amount = floor(";
     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
+    ss << "    if( num < 0 || num >= 281474976710656.0 )\n";
+    ss << "        return CreateDoubleError(IllegalArgument);\n";
     ss << "    return floor(";
     ss << "shift_amount >= 0 ? num / pow(2.0, shift_amount) : ";
     ss << "num * pow(2.0, fabs(shift_amount)));\n";

Reply via email to