xmloff/source/text/txtfldi.cxx |  120 ++++++++++++++++++++---------------------
 1 file changed, 61 insertions(+), 59 deletions(-)

New commits:
commit d634da0adca1191da5c4c54ae17be7185b6bba36
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sat Apr 6 14:34:48 2024 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sat Apr 6 22:11:46 2024 +0200

    flatten for readability
    
    no logic change intended
    
    Change-Id: I27b17634c86bb99d018e2c5991bbc909319e3b4f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165856
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx
index 5c494b70b2e3..72d866de7ed2 100644
--- a/xmloff/source/text/txtfldi.cxx
+++ b/xmloff/source/text/txtfldi.cxx
@@ -3244,83 +3244,82 @@ void 
XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/)
     // reinstall old list item #91964#
     GetImport().GetTextImport()->PopListContext();
 
-    if ( bValid )
+    if (!bValid)
     {
-        if ( mnElement == XML_ELEMENT(OFFICE, XML_ANNOTATION_END) )
+        GetImportHelper().InsertString(GetContent());
+        return;
+    }
+
+    if ( mnElement == XML_ELEMENT(OFFICE, XML_ANNOTATION_END) )
+    {
+        // Search for a previous annotation with the same name.
+        uno::Reference< text::XTextContent > xPrevField;
         {
-            // Search for a previous annotation with the same name.
-            uno::Reference< text::XTextContent > xPrevField;
+            Reference<XTextFieldsSupplier> 
xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
+            if (!xTextFieldsSupplier)
+                return;
+            uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+            uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+            while (xFields->hasMoreElements())
             {
-                Reference<XTextFieldsSupplier> 
xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
-                if (xTextFieldsSupplier)
+                uno::Reference<beans::XPropertySet> 
xCurrField(xFields->nextElement(), uno::UNO_QUERY);
+                uno::Reference<beans::XPropertySetInfo> const xInfo(
+                        xCurrField->getPropertySetInfo());
+                if (xInfo->hasPropertyByName(sAPI_name))
                 {
-                    uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
-                    uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
-                    while (xFields->hasMoreElements())
+                    OUString aFieldName;
+                    xCurrField->getPropertyValue(sAPI_name) >>= aFieldName;
+                    if (aFieldName == aName)
                     {
-                        uno::Reference<beans::XPropertySet> 
xCurrField(xFields->nextElement(), uno::UNO_QUERY);
-                        uno::Reference<beans::XPropertySetInfo> const xInfo(
-                                xCurrField->getPropertySetInfo());
-                        if (xInfo->hasPropertyByName(sAPI_name))
-                        {
-                            OUString aFieldName;
-                            xCurrField->getPropertyValue(sAPI_name) >>= 
aFieldName;
-                            if (aFieldName == aName)
-                            {
-                                xPrevField.set( xCurrField, uno::UNO_QUERY );
-                                break;
-                            }
-                        }
+                        xPrevField.set( xCurrField, uno::UNO_QUERY );
+                        break;
                     }
                 }
             }
-            if ( xPrevField.is() )
-            {
-                // So we are ending a previous annotation,
-                // let's create a text range covering the old and the current 
position.
-                uno::Reference<text::XText> xText = 
GetImportHelper().GetText();
-                uno::Reference<text::XTextCursor> xCursor =
-                    
xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange());
-                try
-                {
-                    xCursor->gotoRange(xPrevField->getAnchor(), true);
-                }
-                catch (const uno::RuntimeException&)
-                {
-                    // Losing the start of the anchor is better than not 
opening the document at
-                    // all.
-                    TOOLS_WARN_EXCEPTION(
-                        "xmloff.text",
-                        "XMLAnnotationImportContext::endFastElement: 
gotoRange() failed: ");
-                }
-
-                xText->insertTextContent(xCursor, xPrevField, 
!xCursor->isCollapsed());
-            }
         }
-        else
+        if ( xPrevField.is() )
         {
-            if ( mxField.is() || CreateField( mxField, sServicePrefix + 
GetServiceName() ) )
+            // So we are ending a previous annotation,
+            // let's create a text range covering the old and the current 
position.
+            uno::Reference<text::XText> xText = GetImportHelper().GetText();
+            uno::Reference<text::XTextCursor> xCursor =
+                
xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange());
+            try
+            {
+                xCursor->gotoRange(xPrevField->getAnchor(), true);
+            }
+            catch (const uno::RuntimeException&)
             {
-                // set field properties
-                PrepareField( mxField );
+                // Losing the start of the anchor is better than not opening 
the document at
+                // all.
+                TOOLS_WARN_EXCEPTION(
+                    "xmloff.text",
+                    "XMLAnnotationImportContext::endFastElement: gotoRange() 
failed: ");
+            }
 
-                // attach field to document
-                Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
+            xText->insertTextContent(xCursor, xPrevField, 
!xCursor->isCollapsed());
+        }
+        return;
+    }
 
-                // workaround for #80606#
-                try
-                {
-                    GetImportHelper().InsertTextContent( xTextContent );
-                }
-                catch (const lang::IllegalArgumentException&)
-                {
-                    // ignore
-                }
-            }
+    if ( mxField.is() || CreateField( mxField, sServicePrefix + 
GetServiceName() ) )
+    {
+        // set field properties
+        PrepareField( mxField );
+
+        // attach field to document
+        Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
+
+        // workaround for #80606#
+        try
+        {
+            GetImportHelper().InsertTextContent( xTextContent );
+        }
+        catch (const lang::IllegalArgumentException&)
+        {
+            // ignore
         }
     }
-    else
-        GetImportHelper().InsertString(GetContent());
 }
 
 void XMLAnnotationImportContext::PrepareField(
commit acc7f7d895f37e573963c3dd6c488346f8da6fbf
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sat Apr 6 14:31:10 2024 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sat Apr 6 22:11:35 2024 +0200

    ofz#67867 Null-dereference READ
    
    Change-Id: Ia4d9097d05c250fffe938b283a3ca623f60b4b7a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165855
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx
index a235d1203d3a..5c494b70b2e3 100644
--- a/xmloff/source/text/txtfldi.cxx
+++ b/xmloff/source/text/txtfldi.cxx
@@ -3252,21 +3252,24 @@ void 
XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/)
             uno::Reference< text::XTextContent > xPrevField;
             {
                 Reference<XTextFieldsSupplier> 
xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
-                uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
-                uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
-                while (xFields->hasMoreElements())
+                if (xTextFieldsSupplier)
                 {
-                    uno::Reference<beans::XPropertySet> 
xCurrField(xFields->nextElement(), uno::UNO_QUERY);
-                    uno::Reference<beans::XPropertySetInfo> const xInfo(
-                            xCurrField->getPropertySetInfo());
-                    if (xInfo->hasPropertyByName(sAPI_name))
+                    uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+                    uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+                    while (xFields->hasMoreElements())
                     {
-                        OUString aFieldName;
-                        xCurrField->getPropertyValue(sAPI_name) >>= aFieldName;
-                        if (aFieldName == aName)
+                        uno::Reference<beans::XPropertySet> 
xCurrField(xFields->nextElement(), uno::UNO_QUERY);
+                        uno::Reference<beans::XPropertySetInfo> const xInfo(
+                                xCurrField->getPropertySetInfo());
+                        if (xInfo->hasPropertyByName(sAPI_name))
                         {
-                            xPrevField.set( xCurrField, uno::UNO_QUERY );
-                            break;
+                            OUString aFieldName;
+                            xCurrField->getPropertyValue(sAPI_name) >>= 
aFieldName;
+                            if (aFieldName == aName)
+                            {
+                                xPrevField.set( xCurrField, uno::UNO_QUERY );
+                                break;
+                            }
                         }
                     }
                 }

Reply via email to