include/svx/gallery1.hxx             |    2 -
 svx/qa/unit/gallery/test_gallery.cxx |    4 ++
 svx/source/gallery2/galbrws1.cxx     |   65 ++++++++++++++++++-----------------
 3 files changed, 39 insertions(+), 32 deletions(-)

New commits:
commit 958c3e7d7cbdfce8bb9950481c243746891f5e0b
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sat Sep 7 20:21:06 2024 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Sep 9 12:15:44 2024 +0200

    enforce null checking of AcquireTheme return
    
    Change-Id: I184603be25be734ec377439622872406ef74898a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173026
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173065
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173070
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/svx/gallery1.hxx b/include/svx/gallery1.hxx
index 97e5f4569a9a..c889435568a3 100644
--- a/include/svx/gallery1.hxx
+++ b/include/svx/gallery1.hxx
@@ -132,7 +132,7 @@ public:
     void                        RenameTheme( const OUString& rOldName, const 
OUString& rNewName );
     bool                        RemoveTheme( const OUString& rThemeName );
 
-    GalleryTheme*               AcquireTheme( std::u16string_view rThemeName, 
SfxListener& rListener );
+    SAL_RET_MAYBENULL GalleryTheme* AcquireTheme( std::u16string_view 
rThemeName, SfxListener& rListener );
     void                        ReleaseTheme( GalleryTheme* pTheme, 
SfxListener& rListener );
 
 public:
diff --git a/svx/qa/unit/gallery/test_gallery.cxx 
b/svx/qa/unit/gallery/test_gallery.cxx
index 7e2df25e14cb..79f0d85c08e8 100644
--- a/svx/qa/unit/gallery/test_gallery.cxx
+++ b/svx/qa/unit/gallery/test_gallery.cxx
@@ -306,6 +306,7 @@ void GalleryObjTest::TestInsertGalleryObject()
 
     // Insert Objects Into Theme
     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, 
aListener);
+    CPPUNIT_ASSERT(pGalleryTheme);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
                                  pGalleryTheme->GetObjectCount());
 
@@ -352,6 +353,7 @@ void GalleryObjTest::TestRemoveGalleryObject()
 
     // Insert Objects Into Theme
     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, 
aListener);
+    CPPUNIT_ASSERT(pGalleryTheme);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
                                  pGalleryTheme->GetObjectCount());
 
@@ -408,6 +410,7 @@ void GalleryObjTest::TestChangePositionGalleryObject()
 
     // Insert Objects Into Theme
     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, 
aListener);
+    CPPUNIT_ASSERT(pGalleryTheme);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
                                  pGalleryTheme->GetObjectCount());
 
@@ -469,6 +472,7 @@ void GalleryObjTest::TestGetThemeNameFromGalleryTheme()
     SfxApplication::GetOrCreate();
 
     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, 
aListener);
+    CPPUNIT_ASSERT(pGalleryTheme);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
                                  pGalleryTheme->GetObjectCount());
 
diff --git a/svx/source/gallery2/galbrws1.cxx b/svx/source/gallery2/galbrws1.cxx
index 51dfd90d4a2c..f17bf7871917 100644
--- a/svx/source/gallery2/galbrws1.cxx
+++ b/svx/source/gallery2/galbrws1.cxx
@@ -359,13 +359,14 @@ void GalleryBrowser1::ImplExecute(std::u16string_view 
rIdent)
 {
     if (rIdent == u"update")
     {
-        GalleryTheme*       pTheme = mpGallery->AcquireTheme( 
GetSelectedTheme(), maLocalListener );
-
-        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-        ScopedVclPtr<VclAbstractDialog> 
aActualizeProgress(pFact->CreateActualizeProgressDialog(mxThemes.get(), 
pTheme));
+        if (GalleryTheme* pTheme = mpGallery->AcquireTheme( 
GetSelectedTheme(), maLocalListener ))
+        {
+            SvxAbstractDialogFactory* pFact = 
SvxAbstractDialogFactory::Create();
+            ScopedVclPtr<VclAbstractDialog> 
aActualizeProgress(pFact->CreateActualizeProgressDialog(mxThemes.get(), 
pTheme));
 
-        aActualizeProgress->Execute();
-        mpGallery->ReleaseTheme( pTheme, maLocalListener );
+            aActualizeProgress->Execute();
+            mpGallery->ReleaseTheme( pTheme, maLocalListener );
+        }
     }
     else if (rIdent == u"delete")
     {
@@ -376,45 +377,47 @@ void GalleryBrowser1::ImplExecute(std::u16string_view 
rIdent)
     }
     else if (rIdent == u"rename")
     {
-        GalleryTheme*   pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), 
maLocalListener );
-        const OUString  aOldName( pTheme->GetName() );
-
-        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-        ScopedVclPtr<AbstractTitleDialog> 
aDlg(pFact->CreateTitleDialog(mxThemes.get(), aOldName));
-
-        if( aDlg->Execute() == RET_OK )
+        if (GalleryTheme* pTheme = mpGallery->AcquireTheme(GetSelectedTheme(), 
maLocalListener))
         {
-            const OUString aNewName( aDlg->GetTitle() );
+            const OUString  aOldName( pTheme->GetName() );
+
+            SvxAbstractDialogFactory* pFact = 
SvxAbstractDialogFactory::Create();
+            ScopedVclPtr<AbstractTitleDialog> 
aDlg(pFact->CreateTitleDialog(mxThemes.get(), aOldName));
 
-            if( !aNewName.isEmpty() && ( aNewName != aOldName ) )
+            if( aDlg->Execute() == RET_OK )
             {
-                OUString  aName( aNewName );
-                sal_uInt16  nCount = 0;
+                const OUString aNewName( aDlg->GetTitle() );
 
-                while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) )
+                if( !aNewName.isEmpty() && ( aNewName != aOldName ) )
                 {
-                    aName = aNewName + " " + OUString::number( nCount );
-                }
+                    OUString  aName( aNewName );
+                    sal_uInt16  nCount = 0;
 
-                mpGallery->RenameTheme( aOldName, aName );
+                    while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 
) )
+                    {
+                        aName = aNewName + " " + OUString::number( nCount );
+                    }
+
+                    mpGallery->RenameTheme( aOldName, aName );
+                }
             }
+            mpGallery->ReleaseTheme( pTheme, maLocalListener );
         }
-        mpGallery->ReleaseTheme( pTheme, maLocalListener );
     }
     else if (rIdent == u"assign")
     {
-        GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), 
maLocalListener );
-
-        if (pTheme && !pTheme->IsReadOnly())
+        if (GalleryTheme* pTheme = mpGallery->AcquireTheme( 
GetSelectedTheme(), maLocalListener ))
         {
+            if (!pTheme->IsReadOnly())
+            {
+                SvxAbstractDialogFactory* pFact = 
SvxAbstractDialogFactory::Create();
+                ScopedVclPtr<AbstractGalleryIdDialog> 
aDlg(pFact->CreateGalleryIdDialog(mxThemes.get(), pTheme));
+                if( aDlg->Execute() == RET_OK )
+                    pTheme->SetId( aDlg->GetId(), true );
+            }
 
-            SvxAbstractDialogFactory* pFact = 
SvxAbstractDialogFactory::Create();
-            ScopedVclPtr<AbstractGalleryIdDialog> 
aDlg(pFact->CreateGalleryIdDialog(mxThemes.get(), pTheme));
-            if( aDlg->Execute() == RET_OK )
-                pTheme->SetId( aDlg->GetId(), true );
+            mpGallery->ReleaseTheme( pTheme, maLocalListener );
         }
-
-        mpGallery->ReleaseTheme( pTheme, maLocalListener );
     }
     else if (rIdent == u"properties")
     {

Reply via email to