[Libreoffice-commits] core.git: Branch 'libreoffice-4-0' - sc/source

Eike Rathke erack at redhat.com
Wed Apr 10 23:22:28 PDT 2013


 sc/source/core/tool/interpr1.cxx |   14 ++++++++++++++
 sc/source/core/tool/scmatrix.cxx |   15 ++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

New commits:
commit 92b0c257cbe590d345adbaddbebebe95f977d8d5
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Apr 11 01:29:22 2013 +0200

    resolved fdo#63403 do not create matrix with 0 rows or cols
    
    Change-Id: Icb0000bde3723c1b37713d0f26ef8305c4a199b8
    (cherry picked from commit 7c3ab3bc15cec211767490823539efcada4fe964)
    Reviewed-on: https://gerrit.libreoffice.org/3321
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 1553a9b..3ed9189 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -4591,6 +4591,13 @@ void ScInterpreter::ScColumn()
                 SCCOL nCols;
                 SCROW nRows;
                 pMyFormulaCell->GetMatColsRows( nCols, nRows);
+                if (nCols == 0)
+                {
+                    // Happens if called via ScViewFunc::EnterMatrix()
+                    // ScFormulaCell::GetResultDimensions() as of course a
+                    // matrix result is not available yet.
+                    nCols = 1;
+                }
                 ScMatrixRef pResMat = GetNewMat( static_cast<SCSIZE>(nCols), 1);
                 if (pResMat)
                 {
@@ -4667,6 +4674,13 @@ void ScInterpreter::ScRow()
                 SCCOL nCols;
                 SCROW nRows;
                 pMyFormulaCell->GetMatColsRows( nCols, nRows);
+                if (nRows == 0)
+                {
+                    // Happens if called via ScViewFunc::EnterMatrix()
+                    // ScFormulaCell::GetResultDimensions() as of course a
+                    // matrix result is not available yet.
+                    nRows = 1;
+                }
                 ScMatrixRef pResMat = GetNewMat( 1, static_cast<SCSIZE>(nRows));
                 if (pResMat)
                 {
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 0a92ffc..e6c2240 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1128,17 +1128,26 @@ size_t ScMatrixImpl::Count(bool bCountStrings) const
 void ScMatrixImpl::CalcPosition(SCSIZE nIndex, SCSIZE& rC, SCSIZE& rR) const
 {
     SCSIZE nRowSize = maMat.size().row;
-    rC = nIndex / nRowSize;
+    SAL_WARN_IF( !nRowSize, "sc", "ScMatrixImpl::CalcPosition: 0 rows!");
+    rC = nRowSize > 1 ? nIndex / nRowSize : nIndex;
     rR = nIndex - rC*nRowSize;
 }
 
 // ============================================================================
 
 ScMatrix::ScMatrix( SCSIZE nC, SCSIZE nR) :
-    pImpl(new ScMatrixImpl(nC, nR)), nRefCnt(0) {}
+    pImpl(new ScMatrixImpl(nC, nR)), nRefCnt(0)
+{
+    SAL_WARN_IF( !nC, "sc", "ScMatrix with 0 columns!");
+    SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
+}
 
 ScMatrix::ScMatrix(SCSIZE nC, SCSIZE nR, double fInitVal) :
-    pImpl(new ScMatrixImpl(nC, nR, fInitVal)), nRefCnt(0) {}
+    pImpl(new ScMatrixImpl(nC, nR, fInitVal)), nRefCnt(0)
+{
+    SAL_WARN_IF( !nC, "sc", "ScMatrix with 0 columns!");
+    SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
+}
 
 ScMatrix::~ScMatrix()
 {


More information about the Libreoffice-commits mailing list