sw/source/core/access/AccessibilityCheck.cxx |   25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

New commits:
commit c796878e6af0fc7c886e813a0010d9402312eb5c
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Oct 21 15:56:25 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Oct 21 17:42:04 2024 +0200

    tdf#163543: check GetDocShell()
    
    Similar to
    commit c5f4fe10589acff4d253cc3d32acaf67c7456bd7
    Author: Caolán McNamara <caolan.mcnam...@collabora.com>
    Date:   Thu Oct 3 15:14:05 2024 +0100
    
        check for null DocShell before deref
    
    Change-Id: I910fb934a36b0e68fd8bda59516c21aa9d27d09a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175338
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 2b6cce2107c8..db35a312a6d2 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -752,6 +752,10 @@ private:
             aBackgroundColor = nParaBackColor;
         else
         {
+            SwDocShell* pDocShell = pTextNode->GetDoc().GetDocShell();
+            if (!pDocShell)
+                return;
+
             OUString sCharStyleName;
             Color nCharStyleBackColor(COL_AUTO);
             if (xProperties->getPropertyValue(u"CharStyleName"_ustr) >>= 
sCharStyleName)
@@ -759,7 +763,7 @@ private:
                 try
                 {
                     uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(
-                        pTextNode->GetDoc().GetDocShell()->GetModel(), 
uno::UNO_QUERY);
+                        pDocShell->GetModel(), uno::UNO_QUERY);
                     uno::Reference<container::XNameAccess> xCont
                         = xStyleFamiliesSupplier->getStyleFamilies();
                     uno::Reference<container::XNameAccess> xStyleFamily(
@@ -1661,6 +1665,14 @@ public:
 
         SwTextNode* pTextNode = pCurrent->GetTextNode();
         SwDoc& rDocument = pTextNode->GetDoc();
+        SwDocShell* pDocShell = rDocument.GetDocShell();
+        if (!pDocShell)
+            return;
+
+        SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+        if (!pWrtShell)
+            return;
+
         auto nParagraphLength = pTextNode->GetText().getLength();
         if (nParagraphLength == 0)
         {
@@ -1668,8 +1680,7 @@ public:
             if (!pPrevTextNode)
                 return;
 
-            SwWrtShell* pWrtShell = rDocument.GetDocShell()->GetWrtShell();
-            if (pWrtShell && 
pPrevTextNode->getLayoutFrame(pWrtShell->GetLayout()))
+            if (pPrevTextNode->getLayoutFrame(pWrtShell->GetLayout()))
             {
                 if (pPrevTextNode->GetText().getLength() == 0)
                 {
@@ -1683,8 +1694,7 @@ public:
         }
         else
         {
-            SwWrtShell* pWrtShell = rDocument.GetDocShell()->GetWrtShell();
-            if (pWrtShell && pTextNode->getLayoutFrame(pWrtShell->GetLayout()))
+            if (pTextNode->getLayoutFrame(pWrtShell->GetLayout()))
             {
                 // Check for excess lines inside this paragraph
                 const OUString& sParagraphText = pTextNode->GetText();
@@ -2391,7 +2401,10 @@ public:
     }
     void check(SwDoc* pDoc) override
     {
-        rtl::Reference<SwXTextDocument> xDoc = 
pDoc->GetDocShell()->GetBaseModel();
+        SwDocShell* pDocShell = pDoc->GetDocShell();
+        if (!pDocShell)
+            return;
+        rtl::Reference<SwXTextDocument> xDoc = pDocShell->GetBaseModel();
         if (!xDoc)
             return;
         uno::Reference<container::XNameAccess> xStyleFamilies = 
xDoc->getStyleFamilies();

Reply via email to