sw/source/core/frmedt/feshview.cxx |   70 +++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 34 deletions(-)

New commits:
commit b3fdd999f87312447d03915585812b3a5cd48141
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Sep 14 20:25:25 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Sep 14 22:17:56 2023 +0200

    unfold SwFEShell::IsShapeDefaultHoriTextDirR2L to something readable
    
    return early on not meeting each successive condition
    
    Change-Id: Iad6c9f8a0a2f2c578609f7584a86c553d75c0792
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156932
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/source/core/frmedt/feshview.cxx 
b/sw/source/core/frmedt/feshview.cxx
index 81f816c7bee8..7b1da09c118f 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -3181,45 +3181,44 @@ Color SwFEShell::GetShapeBackground() const
 */
 bool SwFEShell::IsShapeDefaultHoriTextDirR2L() const
 {
-    bool bRet = false;
-
     // check, if a draw view exists
-    OSL_ENSURE( Imp()->GetDrawView(), "wrong usage of 
SwFEShell::GetShapeBackground - no draw view!");
-    if( Imp()->GetDrawView() )
-    {
-        // determine list of selected objects
-        const SdrMarkList* pMrkList = 
&Imp()->GetDrawView()->GetMarkedObjectList();
-        // check, if exactly one object is selected.
-        OSL_ENSURE( pMrkList->GetMarkCount() == 1, "wrong usage of 
SwFEShell::GetShapeBackground - no selected object!");
-        if ( pMrkList->GetMarkCount() == 1)
-        {
-            // get selected object
-            const SdrObject *pSdrObj = pMrkList->GetMark( 0 
)->GetMarkedSdrObj();
-            // check, if selected object is a shape (drawing object)
-            OSL_ENSURE( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) ==  
nullptr, "wrong usage of SwFEShell::GetShapeBackground - selected object is not 
a drawing object!");
-            if ( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) ==  nullptr )
-            {
-                // determine page frame of the frame the shape is anchored.
-                const SwContact* pContact = GetUserCall(pSdrObj);
-                OSL_ENSURE( pContact, 
"<SwFEShell::IsShapeDefaultHoriTextDirR2L(..)> - missing contact!" );
-                if (!pContact)
-                    return false;
-                const SwFrame* pAnchorFrame = static_cast<const 
SwDrawContact*>(pContact)->GetAnchorFrame( pSdrObj );
-                OSL_ENSURE( pAnchorFrame, "inconsistent model - no anchor at 
shape!");
-                if ( pAnchorFrame )
-                {
-                    const SwPageFrame* pPageFrame = 
pAnchorFrame->FindPageFrame();
-                    OSL_ENSURE( pPageFrame, "inconsistent model - no page!");
-                    if ( pPageFrame )
-                    {
-                        bRet = pPageFrame->IsRightToLeft();
-                    }
-                }
-            }
-        }
-    }
+    OSL_ENSURE(Imp()->GetDrawView(), "wrong usage of 
SwFEShell::GetShapeBackground - no draw view!");
+    if (!Imp()->GetDrawView())
+        return false;
 
-    return bRet;
+    // determine list of selected objects
+    const SdrMarkList& rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
+
+    // check, if exactly one object is selected.
+    OSL_ENSURE(rMrkList.GetMarkCount() == 1, "wrong usage of 
SwFEShell::GetShapeBackground - no selected object!");
+    if (rMrkList.GetMarkCount() != 1)
+        return false;
+
+    // get selected object
+    const SdrObject *pSdrObj = rMrkList.GetMark(0)->GetMarkedSdrObj();
+
+    // check, if selected object is a shape (drawing object)
+    OSL_ENSURE(dynamic_cast<const SwVirtFlyDrawObj*>(pSdrObj) == nullptr, 
"wrong usage of SwFEShell::GetShapeBackground - selected object is not a 
drawing object!");
+    if (dynamic_cast<const SwVirtFlyDrawObj*>(pSdrObj) != nullptr)
+        return false;
+
+    // determine page frame of the frame the shape is anchored.
+    const SwContact* pContact = GetUserCall(pSdrObj);
+    OSL_ENSURE(pContact, "<SwFEShell::IsShapeDefaultHoriTextDirR2L(..)> - 
missing contact!");
+    if (!pContact)
+        return false;
+
+    const SwFrame* pAnchorFrame = static_cast<const 
SwDrawContact*>(pContact)->GetAnchorFrame(pSdrObj);
+    OSL_ENSURE(pAnchorFrame, "inconsistent model - no anchor at shape!");
+    if (!pAnchorFrame)
+        return false;
+
+    const SwPageFrame* pPageFrame = pAnchorFrame->FindPageFrame();
+    OSL_ENSURE(pPageFrame, "inconsistent model - no page!");
+    if (!pPageFrame)
+        return false;
+
+    return pPageFrame->IsRightToLeft();
 }
 
 Point SwFEShell::GetRelativePagePosition(const Point& rDocPos)
commit 105d1c010c4dc3caedf66a2080045c9c5f6fb9e3
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Sep 14 20:18:55 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Sep 14 22:17:47 2023 +0200

    crashreporting: apparent null deref at 
SwFEShell::IsShapeDefaultHoriTextDirR2L
    
    https: 
//crashreport.libreoffice.org/stats/crash_details/73028951-19a0-409b-89d2-a080495df925
    Change-Id: I440465a3c7d5b98ecdd1c5f1973a2b8f64d6772e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156931
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/source/core/frmedt/feshview.cxx 
b/sw/source/core/frmedt/feshview.cxx
index 537070f08c24..81f816c7bee8 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -3200,8 +3200,11 @@ bool SwFEShell::IsShapeDefaultHoriTextDirR2L() const
             if ( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) ==  nullptr )
             {
                 // determine page frame of the frame the shape is anchored.
-                const SwFrame* pAnchorFrame =
-                        
static_cast<SwDrawContact*>(GetUserCall(pSdrObj))->GetAnchorFrame( pSdrObj );
+                const SwContact* pContact = GetUserCall(pSdrObj);
+                OSL_ENSURE( pContact, 
"<SwFEShell::IsShapeDefaultHoriTextDirR2L(..)> - missing contact!" );
+                if (!pContact)
+                    return false;
+                const SwFrame* pAnchorFrame = static_cast<const 
SwDrawContact*>(pContact)->GetAnchorFrame( pSdrObj );
                 OSL_ENSURE( pAnchorFrame, "inconsistent model - no anchor at 
shape!");
                 if ( pAnchorFrame )
                 {

Reply via email to