sw/inc/dcontact.hxx             |    7 ++++---
 sw/source/core/crsr/crstrvl.cxx |    2 ++
 sw/source/core/doc/doc.cxx      |    2 ++
 sw/source/core/doc/docdraw.cxx  |    6 +++---
 sw/source/core/doc/doclay.cxx   |    2 +-
 sw/source/core/undo/undraw.cxx  |    4 ++--
 6 files changed, 14 insertions(+), 9 deletions(-)

New commits:
commit 08d9f27a8f4d5a526b0e207a0bed03c0909322a0
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Sep 9 19:20:45 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Sep 10 08:03:59 2024 +0200

    fix casting of SpzFrameFormat
    
    we need to check before casting the items in GetSpzFrameFormats.
    
    The code in SwCursorShell::SelectNxtPrvHyperlink dates from
        commit 9624a1307c5317652af8961a560a8798029039ee
        Author: jp <j...@openoffice.org>
        Date:   Fri Feb 8 14:06:36 2002 +0000
        Task #96967#: add travel to next/prev hyperlink
    
    and the code in SwDoc::ForEachFormatURL is from
        commit 68566c28b962bf46d3ffc30c635efb37df19a58e
        Author: Noel Grandin <noelgran...@gmail.com>
        Date:   Sun Sep 8 10:29:21 2024 +0200
        dont use GetItemSurrogates for gathering SwFormatURL
    
    (Yes, I spotted the bad code __after__ I copied it, sigh).
    
    Change-Id: Iebbfba06e974bf780b644aa9c563ca23580c6870
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173106
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 96899a9db013..f09b1b146c5e 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -2806,6 +2806,8 @@ bool SwCursorShell::SelectNxtPrvHyperlink( bool bNext )
     {
         for(sw::SpzFrameFormat* pSpz: *GetDoc()->GetSpzFrameFormats())
         {
+            if (pSpz->Which() != RES_FLYFRMFMT)
+                continue;
             auto pFormat = static_cast<SwFlyFrameFormat*>(pSpz);
             const SwFormatURL& rURLItem = pFormat->GetURL();
             if( rURLItem.GetMap() || !rURLItem.GetURL().isEmpty() )
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index c2620093cb33..312250826bf7 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1399,6 +1399,8 @@ void SwDoc::ForEachFormatURL( const 
std::function<bool(const SwFormatURL&)>& rFu
 {
     for(sw::SpzFrameFormat* pSpz : *GetSpzFrameFormats())
     {
+        if (pSpz->Which() != RES_FLYFRMFMT)
+            continue;
         auto pFormat = static_cast<SwFlyFrameFormat*>(pSpz);
         const SwFormatURL& rURLItem = pFormat->GetURL();
         if (!rFunc(rURLItem))
commit e164e61f46d15612e6f3ef1eaaec758bed2a05c7
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Sep 9 20:21:54 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Sep 10 08:03:48 2024 +0200

    fix ubsan, partially revert
    
    this
       commit 43be09b29c28284c6585eaa48117e168f7c9c7b5
       Author: Noel Grandin <noel.gran...@collabora.co.uk>
       Date:   Fri Sep 6 15:27:43 2024 +0200
       return SwDrawFrameFormat  from SwContact::GetFrameFormat
    since we can also have SwFlyFrameFormat* being returned there
    
    Change-Id: Ide064ec39ccb99f3a166b869c552f54f482b9bcd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173108
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/inc/dcontact.hxx b/sw/inc/dcontact.hxx
index 86d816111ace..c924c006fc66 100644
--- a/sw/inc/dcontact.hxx
+++ b/sw/inc/dcontact.hxx
@@ -109,9 +109,10 @@ public:
     virtual const SdrObject *GetMaster() const = 0;
     virtual SdrObject *GetMaster() = 0;
 
-          SwDrawFrameFormat  *GetFormat() { return 
static_cast<SwDrawFrameFormat*>(GetRegisteredIn()); }
-    const SwDrawFrameFormat  *GetFormat() const
-        { return static_cast<const SwDrawFrameFormat*>(GetRegisteredIn()); }
+    /// these two methods return either  SwDrawFrameFormat* or 
SwFltFrameFormat*
+          sw::SpzFrameFormat  *GetFormat() { return 
static_cast<sw::SpzFrameFormat*>(GetRegisteredIn()); }
+    const sw::SpzFrameFormat  *GetFormat() const
+        { return static_cast<const sw::SpzFrameFormat*>(GetRegisteredIn()); }
 
     bool IsInDTOR() const { return mbInDTOR;}
 
diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx
index 0be34d8f9c9f..e9316317c96e 100644
--- a/sw/source/core/doc/docdraw.cxx
+++ b/sw/source/core/doc/docdraw.cxx
@@ -239,7 +239,7 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
                     for (const auto& rTextBoxElement : 
pTextBoxNode->GetAllTextBoxes())
                         vSavedTextBoxes.emplace(rTextBoxElement);
 
-            pFormat = pContact->GetFormat();
+            pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
             // Deletes itself!
             pContact->Changed(*pObj, SdrUserCallType::Delete, 
pObj->GetLastBoundRect() );
             pObj->SetUserCall( nullptr );
@@ -478,7 +478,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView )
             {
                 if (SwDrawContact* pC = 
static_cast<SwDrawContact*>(GetUserCall(pObj)))
                 {
-                    SwDrawFrameFormat* pFrameFormat = pC->GetFormat();
+                    SwDrawFrameFormat* pFrameFormat = 
static_cast<SwDrawFrameFormat*>(pC->GetFormat());
                     if (pFrameFormat
                         && RndStdIds::FLY_AS_CHAR == 
pFrameFormat->GetAnchor().GetAnchorId())
                     {
@@ -508,7 +508,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView )
                     SwDrawContact *pContact = 
static_cast<SwDrawContact*>(pObj->GetUserCall());
                     if( pContact ) // of course not for grouped objects
                     {
-                        SwDrawFrameFormat *pFormat = pContact->GetFormat();
+                        SwDrawFrameFormat *pFormat = 
static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
                         // before delete of selection is performed, marked
                         // <SwDrawVirtObj>-objects have to be replaced by its
                         // reference objects.  Thus, assert, if a
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index bca8a652eae3..bfe18a2411d0 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -1247,7 +1247,7 @@ SwFlyFrameFormat* SwDoc::InsertDrawLabel(
     OSL_ENSURE( RES_DRAWFRMFMT == pContact->GetFormat()->Which(),
             "InsertDrawLabel(): not a DrawFrameFormat" );
 
-    SwDrawFrameFormat* pOldFormat = pContact->GetFormat();
+    SwDrawFrameFormat* pOldFormat = 
static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
     if (!pOldFormat)
         return nullptr;
 
diff --git a/sw/source/core/undo/undraw.cxx b/sw/source/core/undo/undraw.cxx
index f40d03033636..2365c9b57156 100644
--- a/sw/source/core/undo/undraw.cxx
+++ b/sw/source/core/undo/undraw.cxx
@@ -354,7 +354,7 @@ SwUndoDrawUnGroup::SwUndoDrawUnGroup( SdrObjGroup* pObj, 
const SwDoc& rDoc )
 
     if (SwDrawContact *pContact = 
static_cast<SwDrawContact*>(GetUserCall(pObj)))
     {
-        SwDrawFrameFormat* pFormat = pContact->GetFormat();
+        SwDrawFrameFormat* pFormat = 
static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
 
         m_pObjArray[0].pObj = pObj;
         m_pObjArray[0].pFormat = pFormat;
@@ -629,7 +629,7 @@ void SwUndoDrawDelete::RedoImpl(::sw::UndoRedoContext & 
rContext)
         if (!pContact)
             continue;
 
-        SwDrawFrameFormat *pFormat = pContact->GetFormat();
+        SwDrawFrameFormat *pFormat = 
static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
 
         // object will destroy itself
         pContact->Changed( *pObj, SdrUserCallType::Delete, 
pObj->GetLastBoundRect() );

Reply via email to