sw/source/uibase/shells/textfld.cxx |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

New commits:
commit 83b1f6b58a30bdb589e9ce73deef39f021aebde1
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Wed May 3 19:03:49 2023 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Thu May 4 02:46:53 2023 +0200

    tdf#86630 sw page number wizard: avoid crash when no GetCurrFrame
    
    The steps to get the crash were:
    -create a header (and leave the cursor in the header)
    -use the wizard to create a non-mirrored footer
    
    I had seen this crash happening occassionally during development,
    but hadn't yet identified the exact steps to consistently reproduce.
    Thanks to QA who tracked that down.
    
    Although it looks/feels like a hack, it actually works amazingly well.
    The simple act of SetCursorInHdFt "fixes" GetCurrFrame/Get*PageNum,
    but we can't always use that because we don't know whether we
    are on an odd or even or first page when we start, so Goto*Text
    is the best when non-mirroring.
    
    Change-Id: I0e2f28d9c8fd2d1a10afede885b525c42ed08af4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151345
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 63d0db3c0b37..d3b3d6853dff 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -1134,8 +1134,14 @@ FIELD_INSERT:
                 bool bInHF = false;
                 bool bSkipMirror = true;
                 size_t nEvenPage = 0;
-                if (bCreateMirror)
+                if (bCreateMirror || !rSh.GetCurrFrame())
                 {
+                    // Come here if Currframe can't be found, otherwise 
Goto*Text will crash.
+                    // Get*PageNum will also be invalid (0), so we have no 
idea where we are.
+                    // (Since not asking for mirror, the likelihood is that 
the bHeader is shared,
+                    // in which case it doesn't matter anyway, and we just 
hope for the best.)
+                    // Read the code in this block assuming that bCreateMirror 
is true.
+
                     // There are enough pages that there probably is a valid 
odd page.
                     // However, that is not guaranteed: perhaps the page style 
switched,
                     // or a blank page was forced, or some other complexity.
@@ -1173,9 +1179,6 @@ FIELD_INSERT:
                 }
                 else
                 {
-                    // CurrFrame is lost when mirror is created. Goto*Text 
crashes if no CurrFrame
-                    assert(rSh.GetCurrFrame()); // not guaranteed, but 
normally assumed
-
                     if (bHeader)
                         bInHF = rSh.GotoHeaderText();
                     else

Reply via email to