sc/source/core/data/table3.cxx |   75 +++++++++++++++++++++--------------------
 1 file changed, 39 insertions(+), 36 deletions(-)

New commits:
commit 7c0e7e7fbcd90f739b9b8534aa19b39bf1a15c7b
Author: Ahmed GHANMI <agha...@linagora.com>
Date:   Thu Jan 18 10:40:50 2018 +0100

    tdf#114720: Fix subtotal crash
    
    A condition was added in order to not make subtotal
    functions if category was not checked.
    
    Change-Id: I56f11330fa16bf0d3199576ce2545cbc8d13e864
    Reviewed-on: https://gerrit.libreoffice.org/48099
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Eike Rathke <er...@redhat.com>
    (cherry picked from commit 6cb011cc644d8f2e189ce5b8e5de7ff297969840)
    Reviewed-on: https://gerrit.libreoffice.org/48163
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Tested-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index b973dd8fd6bc..f4b63f4f1eaf 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2139,48 +2139,51 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
         }
     }
 
-    // generate global total
-    SCROW nGlobalStartRow = aRowVector[0].nSubStartRow;
-    SCROW nGlobalStartFunc = aRowVector[0].nFuncStart;
-    SCROW nGlobalEndRow = 0;
-    SCROW nGlobalEndFunc = 0;
-    for ( ::std::vector< RowEntry >::const_iterator iEntry( 
aRowVector.begin());
-            iEntry != aRowVector.end(); ++iEntry)
-    {
-        nGlobalEndRow = (nGlobalEndRow < iEntry->nDestRow) ? iEntry->nDestRow 
: nGlobalEndRow;
-        nGlobalEndFunc = (nGlobalEndFunc < iEntry->nFuncEnd) ? 
iEntry->nFuncEnd : nGlobalEndRow;
-    }
-
-    for (sal_uInt16 nLevel=0; nLevel<nLevelCount; nLevel++)
+    if (aRowVector.size() > 0)
     {
-        // increment end row
-        nGlobalEndRow++;
+        // generate global total
+        SCROW nGlobalStartRow = aRowVector[0].nSubStartRow;
+        SCROW nGlobalStartFunc = aRowVector[0].nFuncStart;
+        SCROW nGlobalEndRow = 0;
+        SCROW nGlobalEndFunc = 0;
+        for (::std::vector< RowEntry >::const_iterator 
iEntry(aRowVector.begin());
+             iEntry != aRowVector.end(); ++iEntry)
+        {
+            nGlobalEndRow = (nGlobalEndRow < iEntry->nDestRow) ? 
iEntry->nDestRow : nGlobalEndRow;
+            nGlobalEndFunc = (nGlobalEndFunc < iEntry->nFuncEnd) ? 
iEntry->nFuncEnd : nGlobalEndRow;
+        }
 
-        // add row entry for formula
-        aRowEntry.nGroupNo = nLevelCount-nLevel-1;
-        aRowEntry.nSubStartRow = nGlobalStartRow;
-        aRowEntry.nFuncStart = nGlobalStartFunc;
-        aRowEntry.nDestRow = nGlobalEndRow;
-        aRowEntry.nFuncEnd = nGlobalEndFunc;
+        for (sal_uInt16 nLevel = 0; nLevel<nLevelCount; nLevel++)
+        {
+            // increment end row
+            nGlobalEndRow++;
 
-        // increment row
-        nGlobalEndFunc++;
+            // add row entry for formula
+            aRowEntry.nGroupNo = nLevelCount - nLevel - 1;
+            aRowEntry.nSubStartRow = nGlobalStartRow;
+            aRowEntry.nFuncStart = nGlobalStartFunc;
+            aRowEntry.nDestRow = nGlobalEndRow;
+            aRowEntry.nFuncEnd = nGlobalEndFunc;
 
-        bSpaceLeft = pDocument->InsertRow( 0, nTab, MAXCOL, nTab, 
aRowEntry.nDestRow, 1 );
+            // increment row
+            nGlobalEndFunc++;
 
-        if (bSpaceLeft)
-        {
-            aRowVector.push_back( aRowEntry );
-            nEndRow++;
-            DBShowRow(aRowEntry.nDestRow, true);
+            bSpaceLeft = pDocument->InsertRow(0, nTab, MAXCOL, nTab, 
aRowEntry.nDestRow, 1);
 
-            // insert label
-            ScSubTotalFunc* eResFunc = rParam.pFunctions[aRowEntry.nGroupNo];
-            OUString label = ScGlobal::GetRscString( STR_TABLE_GRAND );
-            label += " ";
-            label += ScGlobal::GetRscString(lcl_GetSubTotalStrId(eResFunc[0]));
-            SetString( nGroupCol[aRowEntry.nGroupNo], aRowEntry.nDestRow, 
nTab, label );
-            ApplyStyle( nGroupCol[aRowEntry.nGroupNo], aRowEntry.nDestRow, 
pStyle );
+            if (bSpaceLeft)
+            {
+                aRowVector.push_back(aRowEntry);
+                nEndRow++;
+                DBShowRow(aRowEntry.nDestRow, true);
+
+                // insert label
+                ScSubTotalFunc* eResFunc = 
rParam.pFunctions[aRowEntry.nGroupNo];
+                OUString label = ScGlobal::GetRscString(STR_TABLE_GRAND);
+                label += " ";
+                label += 
ScGlobal::GetRscString(lcl_GetSubTotalStrId(eResFunc[0]));
+                SetString(nGroupCol[aRowEntry.nGroupNo], aRowEntry.nDestRow, 
nTab, label);
+                ApplyStyle(nGroupCol[aRowEntry.nGroupNo], aRowEntry.nDestRow, 
pStyle);
+            }
         }
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to