[Libreoffice-commits] .: sc/source

Michael Stahl mst at kemper.freedesktop.org
Wed Apr 4 11:42:08 PDT 2012


 sc/source/core/data/sortparam.cxx  |   40 +++++++++++++------------------------
 sc/source/ui/docshell/dbdocfun.cxx |    5 ++--
 2 files changed, 18 insertions(+), 27 deletions(-)

New commits:
commit 61af0e1c3c1c9003c741d64840f9b6f39ea87ead
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Apr 4 20:37:04 2012 +0200

    ScDBDocFunc::Sort: work around STL assertion in sc_unoapi
    
    from dbdocfun.cxx:588:
    error: attempt to subscript container with out-of-bounds index 0,
    but container only holds 0 elements.
    
    The code in sortparam.cxx still looks quite wrong, and
    in table3.cxx there are various arrays hard-coded to size 3...
    
    (regression from a02b445c39d969fedc554fc2c500b88a27a13906)

diff --git a/sc/source/core/data/sortparam.cxx b/sc/source/core/data/sortparam.cxx
index 069e410..21bf327 100644
--- a/sc/source/core/data/sortparam.cxx
+++ b/sc/source/core/data/sortparam.cxx
@@ -175,8 +175,6 @@ ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld )
         aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm ),
         nCompatHeader( rOld.nCompatHeader )
 {
-    sal_uInt16 nNewCount = 0;
-    sal_uInt16 nSortSize = GetSortKeyCount();
     sal_uInt16 i;
 
     //  zuerst die Gruppen aus den Teilergebnissen
@@ -184,42 +182,34 @@ ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld )
         for (i=0; i<MAXSUBTOTAL; i++)
             if (rSub.bGroupActive[i])
             {
-                if (nNewCount < nSortSize)
-                {
-                    maKeyState[nNewCount].bDoSort = true;
-                    maKeyState[nNewCount].nField = rSub.nField[i];
-                    maKeyState[nNewCount].bAscending = rSub.bAscending;
-                    ++nNewCount;
-                }
+#if 0
+// FIXME this crashes in sc_unoapi currently; table3.cxx has nMaxSorts = 3...
+                ScSortKeyState key;
+                key.bDoSort = true;
+                key.nField = rSub.nField[i];
+                key.bAscending = rSub.bAscending;
+                maKeyState.push_back(key);
+#endif
             }
 
     //  dann dahinter die alten Einstellungen
-    for (i=0; i<nSortSize; i++)
+    for (i=0; i < rOld.GetSortKeyCount(); i++)
         if (rOld.maKeyState[i].bDoSort)
         {
             SCCOLROW nThisField = rOld.maKeyState[i].nField;
             bool bDouble = false;
-            for (sal_uInt16 j=0; j<nNewCount; j++)
+            for (sal_uInt16 j = 0; j < GetSortKeyCount(); j++)
                 if ( maKeyState[j].nField == nThisField )
                     bDouble = true;
             if (!bDouble)               // ein Feld nicht zweimal eintragen
             {
-                if (nNewCount < nSortSize)
-                {
-                    maKeyState[nNewCount].bDoSort = true;
-                    maKeyState[nNewCount].nField = nThisField;
-                    maKeyState[nNewCount].bAscending = rOld.maKeyState[i].bAscending;
-                    ++nNewCount;
-                }
+                ScSortKeyState key;
+                key.bDoSort = true;
+                key.nField = nThisField;
+                key.bAscending = rOld.maKeyState[i].bAscending;
+                maKeyState.push_back(key);
             }
         }
-
-    for (i=nNewCount; i<nSortSize; i++)       // Rest loeschen
-    {
-        maKeyState[nNewCount].bDoSort = false;
-        maKeyState[nNewCount].nField = 0;
-        maKeyState[nNewCount].bAscending = true;
-    }
 }
 
 //------------------------------------------------------------------------
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index a54f906..c315147 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -585,7 +585,7 @@ sal_Bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
     }
 
     // don't call ScDocument::Sort with an empty SortParam (may be empty here if bCopy is set)
-    if ( aLocalParam.maKeyState[0].bDoSort )
+    if (aLocalParam.GetSortKeyCount() && aLocalParam.maKeyState[0].bDoSort)
         pDoc->Sort( nTab, aLocalParam, bRepeatQuery );
 
     sal_Bool bSave = sal_True;
@@ -593,7 +593,8 @@ sal_Bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
     {
         ScSortParam aOldSortParam;
         pDBData->GetSortParam( aOldSortParam );
-        if ( aOldSortParam.maKeyState[0].bDoSort && aOldSortParam.bInplace )   // Inplace-Sortierung gemerkt?
+        if (aOldSortParam.GetSortKeyCount() &&
+            aOldSortParam.maKeyState[0].bDoSort && aOldSortParam.bInplace)
         {
             bSave = false;
             aOldSortParam.nDestCol = rSortParam.nDestCol;


More information about the Libreoffice-commits mailing list