sc/inc/columnspanset.hxx              |    1 +
 sc/source/core/data/columnspanset.cxx |    4 ++++
 2 files changed, 5 insertions(+)

New commits:
commit b032101f1e253e83dbed58632882853021d11647
Author:     Kohei Yoshida <ko...@libreoffice.org>
AuthorDate: Thu Mar 2 23:29:15 2023 -0500
Commit:     Kohei Yoshida <ko...@libreoffice.org>
CommitDate: Mon Mar 6 13:38:28 2023 +0000

    tdf#148143: Reset the position hint when flat_segment_tree gets copied
    
    std::optional stores the wrapped object as part of its memory footprint,
    and when it gets copied, it copy-constructs the wrapped object too.  We
    need to be aware of this when using std::optional inside std::vector
    which may reallocate its internal buffer and copy the stored elements.
    
    Change-Id: Ib8fab1295388ae2ee9ef3d044943ac3c2bc8e529
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148152
    Tested-by: Jenkins
    Reviewed-by: Kohei Yoshida <ko...@libreoffice.org>
    (cherry picked from commit c4187189060a104cf36d8a8c9b2958b8c28cde0b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148233

diff --git a/sc/inc/columnspanset.hxx b/sc/inc/columnspanset.hxx
index d8cfc41f524b..5a3dc7645a43 100644
--- a/sc/inc/columnspanset.hxx
+++ b/sc/inc/columnspanset.hxx
@@ -58,6 +58,7 @@ private:
         ColumnSpansType::const_iterator miPos;
 
         ColumnType(SCROW nStart, SCROW nEnd, bool bInit);
+        ColumnType(const ColumnType& rOther);
     };
 
     typedef std::vector<std::optional<ColumnType>> TableType;
diff --git a/sc/source/core/data/columnspanset.cxx 
b/sc/source/core/data/columnspanset.cxx
index eb09ea26be98..bec9c8a7e270 100644
--- a/sc/source/core/data/columnspanset.cxx
+++ b/sc/source/core/data/columnspanset.cxx
@@ -53,6 +53,9 @@ ColRowSpan::ColRowSpan(SCCOLROW nStart, SCCOLROW nEnd) : 
mnStart(nStart), mnEnd(
 ColumnSpanSet::ColumnType::ColumnType(SCROW nStart, SCROW nEnd, bool bInit) :
     maSpans(nStart, nEnd+1, bInit), miPos(maSpans.begin()) {}
 
+ColumnSpanSet::ColumnType::ColumnType(const ColumnType& rOther) :
+    maSpans(rOther.maSpans), miPos(maSpans.begin()) {} // NB: copying maSpans 
invalidates miPos - reset it
+
 ColumnSpanSet::Action::~Action() {}
 void ColumnSpanSet::Action::startColumn(SCTAB /*nTab*/, SCCOL /*nCol*/) {}
 
@@ -142,6 +145,7 @@ void ColumnSpanSet::scan(
 
         ColumnNonEmptyRangesScanner aScanner(rCol.maSpans, bVal);
         ParseBlock(rSrcCells.begin(), rSrcCells, aScanner, nRow1, nRow2);
+        rCol.miPos = rCol.maSpans.begin();
     }
 }
 

Reply via email to