sc/source/ui/view/gridwin.cxx |   39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

New commits:
commit 1c55a61573f7d543976fce4f94d4791ec034c88f
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri May 9 08:50:17 2025 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri May 9 18:04:21 2025 +0200

    crash on null pattern de-ref
    
     #5  0x00007fc235921b20 in ScPatternAttr::GetItem (nWhichP=145, this=0x0) 
at sc/inc/patattr.hxx:164
     #6  ScPatternAttr::GetItem<ScMergeFlagAttr> (nWhich=..., this=0x0) at 
sc/inc/patattr.hxx:167
     #7  ScGridWindow::UpdateCursorOverlay (this=0x0, this@entry=0x39eb3d30)
         at sc/source/ui/view/gridwin.cxx:6610
     #8  0x00007fc235922c0d in ScGridWindow::CursorChanged (this=0x39eb3d30)
         at sc/source/ui/view/gridwin.cxx:6259
     #9  0x00007fc2359c6860 in ScTabView::ShowAllCursors 
(this=this@entry=0x356a9c68)
         at include/rtl/ref.hxx:203
     #10 0x00007fc2359c2586 in ScTabView::PaintBlock 
(this=this@entry=0x356a9c68, bReset=bReset@entry=true)
         at sc/source/ui/view/tabview2.cxx:1286
     #11 0x00007fc2359c271f in ScTabView::DoneBlockMode (this=0x356a9c68, 
bContinue=bContinue@entry=false)
         at sc/source/ui/view/tabview2.cxx:658
     #12 0x00007fc2359c2779 in ScTabView::DoneBlockMode 
(this=this@entry=0x356a9c68, bContinue=bContinue@entry=false)
         at sc/source/ui/view/tabview2.cxx:666
     #13 0x00007fc2359ce0ca in ScTabView::SetTabNo (this=0x356a9c68, nTab=3, 
bNew=<optimized out>, bExtendSelection=false, bSameTabButMoved=<optimized out>)
         at sc/source/ui/view/tabview3.cxx:1965
     #14 0x00007fc2359e851d in ScTabViewShell::Notify (this=0x356a9a60, 
rBC=..., rHint=...)
         at sc/source/ui/view/tabvwsh5.cxx:202
     #15 0x00007fc245e6f935 in __gnu_cxx::__normal_iterator<SvtListener**, 
std::vector<SvtListener*, std::allocator<SvtListener*> > >::__normal_iterator (
         __i=<optimized out>, this=<optimized out>) at 
/opt/rh/devtoolset-12/root/usr/include/c++/12/bits/stl_iterator.h:1073
     #16 std::vector<SvtListener*, std::allocator<SvtListener*> >::end 
(this=<optimized out>) at 
/opt/rh/devtoolset-12/root/usr/include/c++/12/bits/stl_vector.h:889
     #17 SvtBroadcaster::SvtBroadcaster (this=0x2b, rBC=...) at 
svl/source/notify/broadcast.cxx:180
     #18 0x00007ffdb455a730 in ?? ()
     #19 0x0000000000000003 in ?? ()
     #20 0x0000000002476c90 in ?? ()
     #21 0x00007fc244207e01 in avmedia::MediaFloater::setURL (this=0x331fc030, 
rURL=..., rReferer=..., bPlayImmediately=<optimized out>)
         at /opt/rh/devtoolset-12/root/usr/include/c++/12/bits/unique_ptr.h:191
     #22 0x00007fc2498f32e0 in 
com::sun::star::xml::sax::cppu_detail_getUnoType(com::sun::star::xml::sax::XAttributeList
 const*)::the_type ()
        from /opt/collaboraoffice/program/libmergedlo.so
    
    Change-Id: I7d62f67a840fe6c27b7bcf80fdaf66dff8c270c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185088
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 7999585bd83783282bd2ab7025f3fd7f676e7c41)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185091
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 2a73bc1857fa..45a0609940b3 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -6583,22 +6583,24 @@ void ScGridWindow::UpdateCursorOverlay()
         if (maVisibleRange.mnCol2 < nX || maVisibleRange.mnRow2 < nY)
             return;     // no further check needed, nothing visible
 
-        // fdo#87382 Also display the cell cursor for the visible part of
-        // merged cells if the view position is part of merged cells.
-        const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE);
-        if (rMerge.GetColMerge() <= 1 && rMerge.GetRowMerge() <= 1)
-            return;     // not merged and invisible
+        if (pPattern)
+        {
+            // fdo#87382 Also display the cell cursor for the visible part of
+            // merged cells if the view position is part of merged cells.
+            const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE);
+            if (rMerge.GetColMerge() <= 1 && rMerge.GetRowMerge() <= 1)
+                return;     // not merged and invisible
 
-        SCCOL nX2 = nX + rMerge.GetColMerge() - 1;
-        SCROW nY2 = nY + rMerge.GetRowMerge() - 1;
-        // Check if the middle or tail of the merged range is visible.
-        if (maVisibleRange.mnCol1 > nX2 || maVisibleRange.mnRow1 > nY2)
-            return;     // no visible part
+            SCCOL nX2 = nX + rMerge.GetColMerge() - 1;
+            SCROW nY2 = nY + rMerge.GetRowMerge() - 1;
+            // Check if the middle or tail of the merged range is visible.
+            if (maVisibleRange.mnCol1 > nX2 || maVisibleRange.mnRow1 > nY2)
+                return;     // no visible part
+        }
     }
 
     //  don't show the cursor in overlapped cells
-    const ScMergeFlagAttr& rMergeFlag = pPattern->GetItem(ATTR_MERGE_FLAG);
-    bool bOverlapped = rMergeFlag.IsOverlapped();
+    const bool bOverlapped = pPattern && 
pPattern->GetItem(ATTR_MERGE_FLAG).IsOverlapped();
 
     //  left or above of the screen?
     bool bVis = comphelper::LibreOfficeKit::isActive() || ( 
nX>=mrViewData.GetPosX(eHWhich) && nY>=mrViewData.GetPosY(eVWhich) );
@@ -6606,11 +6608,14 @@ void ScGridWindow::UpdateCursorOverlay()
     {
         SCCOL nEndX = nX;
         SCROW nEndY = nY;
-        const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE);
-        if (rMerge.GetColMerge() > 1)
-            nEndX += rMerge.GetColMerge()-1;
-        if (rMerge.GetRowMerge() > 1)
-            nEndY += rMerge.GetRowMerge()-1;
+        if (pPattern)
+        {
+            const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE);
+            if (rMerge.GetColMerge() > 1)
+                nEndX += rMerge.GetColMerge()-1;
+            if (rMerge.GetRowMerge() > 1)
+                nEndY += rMerge.GetRowMerge()-1;
+        }
         bVis = ( nEndX>=mrViewData.GetPosX(eHWhich) && 
nEndY>=mrViewData.GetPosY(eVWhich) );
     }
 

Reply via email to