sc/inc/segmenttree.hxx              |    2 +-
 sc/source/core/data/segmenttree.cxx |   30 +++++++++++++++---------------
 2 files changed, 16 insertions(+), 16 deletions(-)

New commits:
commit fd4384c59eefc8f34d5fe90929d7cb44ee15b27f
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Mon Feb 7 18:06:12 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue Feb 8 12:26:18 2022 +0100

    avoid overflows in ScFlatUInt16RowSegments
    
    Loading a document with >1024 columns caused overflow warnings.
    
    Change-Id: I723185eadf0ed1e806c9fd693ed35dc47d8c2135
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129632
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/inc/segmenttree.hxx b/sc/inc/segmenttree.hxx
index 8dbebaf749d1..c980f9db56a0 100644
--- a/sc/inc/segmenttree.hxx
+++ b/sc/inc/segmenttree.hxx
@@ -149,7 +149,7 @@ public:
     void setValueIf(SCROW nRow1, SCROW nRow2, sal_uInt16 nValue,
                     const std::function<bool(sal_uInt16)>& rPredicate);
     sal_uInt16 getValue(SCROW nRow);
-    sal_uInt32 getSumValue(SCROW nRow1, SCROW nRow2);
+    sal_uInt64 getSumValue(SCROW nRow1, SCROW nRow2);
     bool getRangeData(SCROW nRow, RangeData& rData);
     void removeSegment(SCROW nRow1, SCROW nRow2);
     void insertSegment(SCROW nRow, SCROW nSize);
diff --git a/sc/source/core/data/segmenttree.cxx 
b/sc/source/core/data/segmenttree.cxx
index f57578149e0f..a71e310ab641 100644
--- a/sc/source/core/data/segmenttree.cxx
+++ b/sc/source/core/data/segmenttree.cxx
@@ -162,17 +162,17 @@ ScFlatSegmentsImpl<ValueType_, 
ExtValueType_>::getSumValue(SCCOLROW nPos1, SCCOL
             return 0;
         aData.mnPos2 = aData.mnPos2-1; // end point is not inclusive.
 
-        sal_uInt32 nValue = 0;
+        sal_uInt64 nValue = 0;
 
         SCROW nCurPos = nPos1;
         SCROW nEndPos = aData.mnPos2;
         while (nEndPos <= nPos2)
         {
-            sal_uInt32 nRes;
-            if (o3tl::checked_multiply<sal_uInt32>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
+            sal_uInt64 nRes;
+            if (o3tl::checked_multiply<sal_uInt64>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
             {
                 SAL_WARN("sc.core", "row height overflow");
-                nRes = SAL_MAX_INT32;
+                nRes = SAL_MAX_INT64;
             }
             nValue = o3tl::saturating_add(nValue, nRes);
             nCurPos = nEndPos + 1;
@@ -186,11 +186,11 @@ ScFlatSegmentsImpl<ValueType_, 
ExtValueType_>::getSumValue(SCCOLROW nPos1, SCCOL
         if (nCurPos <= nPos2)
         {
             nEndPos = ::std::min(nEndPos, nPos2);
-            sal_uInt32 nRes;
-            if (o3tl::checked_multiply<sal_uInt32>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
+            sal_uInt64 nRes;
+            if (o3tl::checked_multiply<sal_uInt64>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
             {
                 SAL_WARN("sc.core", "row height overflow");
-                nRes = SAL_MAX_INT32;
+                nRes = SAL_MAX_INT64;
             }
             nValue = o3tl::saturating_add(nValue, nRes);
         }
@@ -202,17 +202,17 @@ ScFlatSegmentsImpl<ValueType_, 
ExtValueType_>::getSumValue(SCCOLROW nPos1, SCCOL
         if (!getRangeDataLeaf(nPos1, aData))
             return 0;
 
-        sal_uInt32 nValue = 0;
+        sal_uInt64 nValue = 0;
 
         SCROW nCurPos = nPos1;
         SCROW nEndPos = aData.mnPos2;
         while (nEndPos <= nPos2)
         {
-            sal_uInt32 nRes;
-            if (o3tl::checked_multiply<sal_uInt32>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
+            sal_uInt64 nRes;
+            if (o3tl::checked_multiply<sal_uInt64>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
             {
                 SAL_WARN("sc.core", "row height overflow");
-                nRes = SAL_MAX_INT32;
+                nRes = SAL_MAX_INT64;
             }
             nValue = o3tl::saturating_add(nValue, nRes);
             nCurPos = nEndPos + 1;
@@ -224,11 +224,11 @@ ScFlatSegmentsImpl<ValueType_, 
ExtValueType_>::getSumValue(SCCOLROW nPos1, SCCOL
         if (nCurPos <= nPos2)
         {
             nEndPos = ::std::min(nEndPos, nPos2);
-            sal_uInt32 nRes;
-            if (o3tl::checked_multiply<sal_uInt32>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
+            sal_uInt64 nRes;
+            if (o3tl::checked_multiply<sal_uInt64>(aData.mnValue, nEndPos - 
nCurPos + 1, nRes))
             {
                 SAL_WARN("sc.core", "row height overflow");
-                nRes = SAL_MAX_INT32;
+                nRes = SAL_MAX_INT64;
             }
             nValue = o3tl::saturating_add(nValue, nRes);
         }
@@ -645,7 +645,7 @@ sal_uInt16 ScFlatUInt16RowSegments::getValue(SCROW nRow)
     return mpImpl->getValue(static_cast<SCCOLROW>(nRow));
 }
 
-sal_uInt32 ScFlatUInt16RowSegments::getSumValue(SCROW nRow1, SCROW nRow2)
+sal_uInt64 ScFlatUInt16RowSegments::getSumValue(SCROW nRow1, SCROW nRow2)
 {
     return mpImpl->getSumValue(static_cast<SCCOLROW>(nRow1), 
static_cast<SCCOLROW>(nRow2));
 }

Reply via email to