Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3869

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/69/3869/1

cppcheck: fix arrayIndexThenCheck/optimize loops

Change-Id: If399abf5fb3eaea91f4f5d5e86b86b37790d3c9a
---
M sc/source/core/data/document.cxx
1 file changed, 15 insertions(+), 10 deletions(-)



diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 8da6a51..d0ec99d 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1831,9 +1831,10 @@
     {
         bool bOldAutoCalc = pDestDoc->GetAutoCalc();
         pDestDoc->SetAutoCalc( false );     // avoid multiple calculations
-        for (SCTAB i = nTab1; i <= nTab2 && i < static_cast<SCTAB>(maTabs.size()); i++)
+        SCTAB nMinSizeBothTabs = static_cast<SCTAB>(std::min(maTabs.size(), 
pDestDoc->maTabs.size()));
+        for (SCTAB i = nTab1; i <= nTab2 && i < nMinSizeBothTabs; i++)
         {
-            if (maTabs[i] && i < static_cast<SCTAB>(pDestDoc->maTabs.size()) && 
pDestDoc->maTabs[i])
+            if (maTabs[i] && pDestDoc->maTabs[i])
                 maTabs[i]->CopyToTable( nCol1, nRow1, nCol2, nRow2, nFlags,
                                       bOnlyMarked, pDestDoc->maTabs[i], pMarks,
                                       false, bColRowFlags );
@@ -1884,8 +1885,9 @@
         pDestDoc->aDocName = aDocName;
     bool bOldAutoCalc = pDestDoc->GetAutoCalc();
     pDestDoc->SetAutoCalc( false );     // avoid multiple calculations
-    for (SCTAB i = aNewRange.aStart.Tab(); i <= aNewRange.aEnd.Tab() && i < 
static_cast<SCTAB>(maTabs.size()); i++)
-        if (maTabs[i] && i < static_cast<SCTAB>(pDestDoc->maTabs.size()) && pDestDoc->maTabs[i])
+    SCTAB nMinSizeBothTabs = static_cast<SCTAB>(std::min(maTabs.size(), pDestDoc->maTabs.size()));
+    for (SCTAB i = aNewRange.aStart.Tab(); i <= aNewRange.aEnd.Tab() && i < nMinSizeBothTabs; i++)
+        if (maTabs[i] && pDestDoc->maTabs[i])
             maTabs[i]->CopyToTable(aNewRange.aStart.Col(), aNewRange.aStart.Row(),
                                  aNewRange.aEnd.Col(), aNewRange.aEnd.Row(),
                                  nFlags, bOnlyMarked, pDestDoc->maTabs[i],
@@ -1908,9 +1910,10 @@
     if (nTab1 > 0)
         CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTab1-1, IDF_FORMULA, false, pDestDoc, pMarks );
 
-    for (SCTAB i = nTab1; i <= nTab2 && i < static_cast<SCTAB>(maTabs.size()); i++)
+    SCTAB nMinSizeBothTabs = static_cast<SCTAB>(std::min(maTabs.size(), pDestDoc->maTabs.size()));
+    for (SCTAB i = nTab1; i <= nTab2 && i < nMinSizeBothTabs; i++)
     {
-        if (maTabs[i] && i < static_cast<SCTAB>(pDestDoc->maTabs.size()) && pDestDoc->maTabs[i])
+        if (maTabs[i] && pDestDoc->maTabs[i])
             maTabs[i]->UndoToTable(aNewRange.aStart.Col(), aNewRange.aStart.Row(),
                                     aNewRange.aEnd.Col(), aNewRange.aEnd.Row(),
                                     nFlags, bOnlyMarked, pDestDoc->maTabs[i], pMarks);
@@ -2181,8 +2184,9 @@
         return;
 
     std::set<sal_uInt16> aUsedNames;        // indexes of named ranges that are used in the copied 
cells
-    for (SCTAB i = 0; i < static_cast<SCTAB>(maTabs.size()); ++i)
-        if (maTabs[i] && i < static_cast<SCTAB>(pClipDoc->maTabs.size()) && pClipDoc->maTabs[i])
+    SCTAB nMinSizeBothTabs = static_cast<SCTAB>(std::min(maTabs.size(), pClipDoc->maTabs.size()));
+    for (SCTAB i = 0; i < nMinSizeBothTabs; ++i)
+        if (maTabs[i] && pClipDoc->maTabs[i])
             if ( bAllTabs || !pMarks || pMarks->GetTableSelect(i) )
                 maTabs[i]->FindRangeNamesInUse(
                     rClipRange.aStart.Col(), rClipRange.aStart.Row(),
@@ -2843,8 +2847,9 @@
 {
     SCTAB nTab1 = rRange.aStart.Tab();
     SCTAB nTab2 = rRange.aEnd.Tab();
-    for (SCTAB i = nTab1; i <= nTab2 && i < static_cast<SCTAB>(maTabs.size()); i++)
-        if (maTabs[i] && i < static_cast<SCTAB>(pSrcDoc->maTabs.size()) && pSrcDoc->maTabs[i])
+    SCTAB nMinSizeBothTabs = static_cast<SCTAB>(std::min(maTabs.size(), pSrcDoc->maTabs.size()));
+    for (SCTAB i = nTab1; i <= nTab2 && i < nMinSizeBothTabs; i++)
+        if (maTabs[i] && pSrcDoc->maTabs[i])
             maTabs[i]->MixData( rRange.aStart.Col(), rRange.aStart.Row(),
                                 rRange.aEnd.Col(), rRange.aEnd.Row(),
                                 nFunction, bSkipEmpty, pSrcDoc->maTabs[i] );

-- 
To view, visit https://gerrit.libreoffice.org/3869
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If399abf5fb3eaea91f4f5d5e86b86b37790d3c9a
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Julien Nabet <serval2412@yahoo.fr>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.