sw/source/core/fields/reffld.cxx |    6 ++++++
 1 file changed, 6 insertions(+)

New commits:
commit 96ed0ae5e35fbcf0f97a5dc8b6dff211579be893
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Sat Jan 11 11:48:29 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Jan 11 14:32:40 2025 +0100

    tdf#164620 CRASH: selecting all and deleting
    
    regression from
        commit 73a46895c5927d68a222b13dc811ea1cceb811a1
        Author: Noel Grandin <noel.gran...@collabora.co.uk>
        Date:   Thu Dec 5 07:58:44 2024 +0200
        tdf#119840 speed up SearchForStyleAnchor
    
    We are dealing with a dangling pointer here, so I'm not sure if this
    change will be sufficient.
    We are very deep inside a series of listener callbacks and events here,
    so no idea how to fix the actual problem i.e. not having a dangling
    pointer at all.
    
    Change-Id: I8314cd0f906e3b2652e10e55dfe8396abdf02856
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180111
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index a063586b482f..75b2f5db7b6a 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1606,6 +1606,12 @@ SwTextNode* 
SwGetRefFieldType::FindAnchorRefStyleOther(SwDoc* pDoc,
 
     SwNodeOffset nReference = pReference->GetIndex();
     const SwNodes& nodes = pDoc->GetNodes();
+
+    // It is possible to end up here, with a pReference pointer which points 
to a node which has already been
+    // removed from the nodes array, which means that calling GetIndex() 
returns an incorrect index.
+    if (nReference >= nodes.Count() || nodes[nReference] != pReference)
+        nReference = nodes.Count() - 1;
+
     SwTextNode* pTextNd = nullptr;
 
     // 1. Search up until we hit the top of the document

Reply via email to