sc/source/core/tool/compiler.cxx |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

New commits:
commit c7e9e3a35c00cae8cea13cbef1de9c696a881cdb
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Jan 29 10:53:32 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Feb 7 22:28:03 2024 +0100

    ofz: Use-of-uninitialized-value
    
    keep a high water mark of the highest initialized level
    
    Change-Id: Ib799331c523209c4f165dc4c40317e25b6b0cc7c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162624
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 63b1f0969225..c9934c26fff6 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4738,6 +4738,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( 
const OUString& rFormul
     pFunctionStack[0].eOp = ocNone;
     pFunctionStack[0].nSep = 0;
     size_t nFunction = 0;
+    size_t nHighWatermark = 0;
     short nBrackets = 0;
     bool bInArray = false;
     eLastOp = ocOpen;
@@ -4757,6 +4758,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( 
const OUString& rFormul
                     ++nFunction;
                     pFunctionStack[ nFunction ].eOp = eLastOp;
                     pFunctionStack[ nFunction ].nSep = 0;
+                    nHighWatermark = nFunction;
                 }
             }
             break;
@@ -4795,6 +4797,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( 
const OUString& rFormul
                     ++nFunction;
                     pFunctionStack[ nFunction ].eOp = eOp;
                     pFunctionStack[ nFunction ].nSep = 0;
+                    nHighWatermark = nFunction;
                 }
             }
             break;
@@ -4825,6 +4828,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( 
const OUString& rFormul
                     ++nFunction;
                     pFunctionStack[ nFunction ].eOp = eOp;
                     pFunctionStack[ nFunction ].nSep = 0;
+                    nHighWatermark = nFunction;
                 }
             }
             break;
@@ -4867,9 +4871,9 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( 
const OUString& rFormul
             // Append a parameter for WEEKNUM, all 1.0
             // Function is already closed, parameter count is nSep+1
             size_t nFunc = nFunction + 1;
-            if (eOp == ocClose &&
-                    (pFunctionStack[ nFunc ].eOp == ocWeek &&   // 2nd week 
start
-                     pFunctionStack[ nFunc ].nSep == 0))
+            if (eOp == ocClose && nFunc <= nHighWatermark &&
+                     pFunctionStack[ nFunc ].nSep == 0 &&
+                     pFunctionStack[ nFunc ].eOp == ocWeek)   // 2nd week start
             {
                 if (    !static_cast<ScTokenArray*>(pArr)->Add( new 
FormulaToken( svSep, ocSep)) ||
                         !static_cast<ScTokenArray*>(pArr)->Add( new 
FormulaDoubleToken( 1.0)))

Reply via email to