formula/source/core/api/token.cxx        |   13 +++-----
 sc/source/core/inc/interpre.hxx          |   12 +++++++
 sc/source/core/tool/interpr1.cxx         |    4 +-
 sc/source/core/tool/interpr4.cxx         |   10 +++++-
 sc/source/ui/view/gridwin4.cxx           |   15 +++++----
 svtools/source/control/ctrltool.cxx      |    5 ---
 sw/source/ui/config/optload.cxx          |    9 ++---
 sw/source/ui/fldui/flddb.cxx             |   25 +++++++---------
 sw/source/ui/fldui/fldfunc.cxx           |    2 -
 sw/source/ui/fldui/fldref.cxx            |   17 +++++------
 sw/source/ui/fmtui/tmpdlg.cxx            |   34 +++++++++++++---------
 sw/source/ui/frmdlg/frmpage.cxx          |   30 +++++++++++++------
 sw/source/ui/frmdlg/wrap.cxx             |    4 +-
 sw/source/uibase/app/appopt.cxx          |   47 +++++++++++++++++--------------
 sw/source/uibase/utlui/content.cxx       |   11 ++++---
 sw/source/uibase/utlui/glbltree.cxx      |   17 ++++++-----
 vcl/source/filter/itiff/itiff.cxx        |   13 +++++---
 vcl/source/filter/png/PngImageWriter.cxx |    9 +++--
 18 files changed, 163 insertions(+), 114 deletions(-)

New commits:
commit 23c6e51e85effe912d0facca39ba8d3a74d04710
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Fri Feb 17 21:32:20 2023 +0200
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:30 2023 +0100

    tdf#147739: Medium is not a synonym of normal
    
    For some reason, medium was thought to be a synonym of normal, but that
    is not the case. Seems to be from:
    
    commit b05701988492b051b3bb07bb46ae0397e23f032f
    Author: th <t...@openoffice.org>
    Date:   Fri Mar 9 14:44:26 2001 +0000
    
        #83090# - Extensions for localized sytle names
        #77189# - FontAlias should now also work
        Extensions for Chinese fontsize numbers
    
    Change-Id: Ic5e463b6e77c0fa88701108597c99c9fa0c6bf4e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147258
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>
    (cherry picked from commit 0c9448bb31a32a3bf4004d45c4b1305debf1b5e2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147249
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/svtools/source/control/ctrltool.cxx 
b/svtools/source/control/ctrltool.cxx
index 508ee9b9092b..0a406b708c76 100644
--- a/svtools/source/control/ctrltool.cxx
+++ b/svtools/source/control/ctrltool.cxx
@@ -452,8 +452,6 @@ OUString FontList::GetStyleName(const FontMetric& rInfo) 
const
             aStyleName = maNormal;
         else if (aCompareStyleName == "regular")
             aStyleName = maNormal;
-        else if (aCompareStyleName == "medium")
-            aStyleName = maNormal;
         else if (aCompareStyleName == "light")
             aStyleName = maLight;
         else if (aCompareStyleName == "lightitalic")
@@ -483,9 +481,6 @@ OUString FontList::GetStyleName(const FontMetric& rInfo) 
const
             aStyleName = SvtResId(STR_SVT_STYLE_EXTRALIGHT);
         else if (aCompareStyleName == "extralightitalic")
             aStyleName = SvtResId(STR_SVT_STYLE_EXTRALIGHT_ITALIC);
-        /* Medium is synonym with Normal */
-        else if (aCompareStyleName == "mediumitalic")
-            aStyleName = maNormalItalic;
         else if (aCompareStyleName == "oblique")
             aStyleName = SvtResId(STR_SVT_STYLE_OBLIQUE);
         else if (aCompareStyleName == "semibold")
commit e00fa4434ed37ac370b10a73f85e13692792d09c
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Fri Feb 17 12:03:54 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:30 2023 +0100

    Stack check safety belt before fishing in muddy waters
    
    Have it hit hard in debug builds.
    
    Change-Id: I9ea54844a0661fd7a75616a2876983a74b2d5bad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147205
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 9d91fbba6f374fa1c10b38eae003da89bd4e6d4b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147244
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 85d2955003af..a6bd98320f71 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -221,6 +221,7 @@ private:
     inline bool MustHaveParamCount( short nAct, short nMust );
     inline bool MustHaveParamCount( short nAct, short nMust, short nMax );
     inline bool MustHaveParamCountMin( short nAct, short nMin );
+    inline bool MustHaveParamCountMinWithStackCheck( short nAct, short nMin );
     void PushParameterExpected();
     void PushIllegalParameter();
     void PushIllegalArgument();
@@ -1074,6 +1075,17 @@ inline bool ScInterpreter::MustHaveParamCountMin( short 
nAct, short nMin )
     return false;
 }
 
+inline bool ScInterpreter::MustHaveParamCountMinWithStackCheck( short nAct, 
short nMin )
+{
+    assert(sp >= nAct);
+    if (sp < nAct)
+    {
+        PushParameterExpected();
+        return false;
+    }
+    return MustHaveParamCountMin( nAct, nMin);
+}
+
 inline bool ScInterpreter::CheckStringPositionArgument( double & fVal )
 {
     if (!std::isfinite( fVal))
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index d82acb37494c..405d9fe00023 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -7643,7 +7643,7 @@ void ScInterpreter::ScVLookup()
 void ScInterpreter::ScSubTotal()
 {
     sal_uInt8 nParamCount = GetByte();
-    if ( !MustHaveParamCountMin( nParamCount, 2 ) )
+    if ( !MustHaveParamCountMinWithStackCheck( nParamCount, 2 ) )
         return;
 
     // We must fish the 1st parameter deep from the stack! And push it on top.
@@ -7690,7 +7690,7 @@ void ScInterpreter::ScSubTotal()
 void ScInterpreter::ScAggregate()
 {
     sal_uInt8 nParamCount = GetByte();
-    if ( !MustHaveParamCountMin( nParamCount, 3 ) )
+    if ( !MustHaveParamCountMinWithStackCheck( nParamCount, 3 ) )
         return;
 
     const FormulaError nErr = nGlobalError;
commit 7aec31583c1c47809c5b79e5b747939972bc7cad
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Feb 17 12:44:03 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:30 2023 +0100

    sc: fix divide by zero in ScGridWindow::DrawPagePreview
    
    Seen in 
https://crashreport.libreoffice.org/stats/signature/ScGridWindow::DrawPagePreview(short,long,short,long,OutputDevice%20&)
    
    Change-Id: Iff64d0fe84c7d53b18db38598709ac47475a6715
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147234
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index d906c1d24c36..259f5032d0a7 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -2039,13 +2039,16 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW 
nY1, SCCOL nX2, SCROW nY2,
                                 //  find right font size for DrawText
                                 aFont.SetFontSize( Size( 0,100 ) );
                                 rRenderContext.SetFont( aFont );
-                                Size aSize100(rRenderContext.GetTextWidth( 
aThisPageStr ), rRenderContext.GetTextHeight() );
 
-                                //  40% of width or 60% of height
-                                tools::Long nSizeX = 40 * ( aPageEnd.X() - 
aPageStart.X() ) / aSize100.Width();
-                                tools::Long nSizeY = 60 * ( aPageEnd.Y() - 
aPageStart.Y() ) / aSize100.Height();
-                                aFont.SetFontSize( Size( 
0,std::min(nSizeX,nSizeY) ) );
-                                rRenderContext.SetFont( aFont );
+                                Size aSize100(rRenderContext.GetTextWidth( 
aThisPageStr ), rRenderContext.GetTextHeight() );
+                                if (aSize100.Width() && aSize100.Height())
+                                {
+                                    //  40% of width or 60% of height
+                                    tools::Long nSizeX = 40 * ( aPageEnd.X() - 
aPageStart.X() ) / aSize100.Width();
+                                    tools::Long nSizeY = 60 * ( aPageEnd.Y() - 
aPageStart.Y() ) / aSize100.Height();
+                                    aFont.SetFontSize( Size( 
0,std::min(nSizeX,nSizeY) ) );
+                                    rRenderContext.SetFont( aFont );
+                                }
 
                                 //  centered output with DrawText
                                 Size aTextSize(rRenderContext.GetTextWidth( 
aThisPageStr ), rRenderContext.GetTextHeight() );
commit 985d534b91c9a5f4e3f616a9b4b9093908912a73
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Feb 16 12:38:55 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:30 2023 +0100

    check GetActiveWrtShell() and CheckAndGetWrtShell()
    
    See 
https://crashreport.libreoffice.org/stats/signature/SwModule::ApplyItemSet(unsigned%20short,SfxItemSet%20const%20&)
    Change-Id: I7c719c5fe4cda9f6571592c30f39bd440053dbe9
    
    Change-Id: Iaa4448dccd1a0ec1aefa539e476b5046ed50f7b7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147201
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/ui/config/optload.cxx b/sw/source/ui/config/optload.cxx
index 93d6b7e4dabe..2c3ef5adbe4e 100644
--- a/sw/source/ui/config/optload.cxx
+++ b/sw/source/ui/config/optload.cxx
@@ -464,10 +464,11 @@ SwCaptionOptPage::SwCaptionOptPage(weld::Container* 
pPage, weld::DialogControlle
     SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_FRAME, m_sText);
     SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_DRAWING, m_sDrawing);
 
-    SwWrtShell* pSh = ::GetActiveWrtShell();
 
     // m_xFormatBox
     sal_uInt16 nSelFormat = SVX_NUM_ARABIC;
+    SwWrtShell* pSh = ::GetActiveWrtShell();
+
     if (pSh)
     {
         for ( auto i = m_pMgr->GetFieldTypeCount(); i; )
@@ -663,13 +664,12 @@ void SwCaptionOptPage::UpdateEntry(int nSelEntry)
         m_xCategory->set_sensitive(bChecked);
         m_xPreview->set_sensitive(bChecked);
 
-        SwWrtShell *pSh = ::GetActiveWrtShell();
 
         InsCaptionOpt* pOpt = 
weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(nSelEntry));
 
         m_xCategoryBox->clear();
         m_xCategoryBox->append_text(m_sNone);
-        if (pSh)
+        if (::GetActiveWrtShell())
         {
             const size_t nCount = m_pMgr->GetFieldTypeCount();
 
@@ -867,8 +867,7 @@ void SwCaptionOptPage::InvalidatePreview()
                 aStr += m_xCategoryBox->get_active_text() + " ";
             }
 
-            SwWrtShell *pSh = ::GetActiveWrtShell();
-            if (pSh)
+            if (SwWrtShell *pSh = ::GetActiveWrtShell())
             {
                 SwSetExpFieldType* pFieldType = 
static_cast<SwSetExpFieldType*>(m_pMgr->GetFieldType(
                                                 SwFieldIds::SetExp, 
m_xCategoryBox->get_active_text() ));
diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx
index 3293a6bc670d..62dd538f01e0 100644
--- a/sw/source/ui/fldui/flddb.cxx
+++ b/sw/source/ui/fldui/flddb.cxx
@@ -73,7 +73,7 @@ SwFieldDBPage::SwFieldDBPage(weld::Container* pPage, 
weld::DialogController* pCo
 SwFieldDBPage::~SwFieldDBPage()
 {
     // If we have no stored SwWrtShell, it means we didn't do anything useful 
- no need to revoke.
-    if (SwWrtShell* pSh = GetWrtShell())
+    if (SwWrtShell* pSh = CheckAndGetWrtShell())
     {
         // This would cleanup in the case of cancelled dialog
         SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager();
@@ -140,8 +140,7 @@ void SwFieldDBPage::Reset(const SfxItemSet*)
         }
         else
         {
-            SwWrtShell *pSh = CheckAndGetWrtShell();
-            if(pSh)
+            if (SwWrtShell *pSh = CheckAndGetWrtShell())
             {
                 SwDBData aTmp(pSh->GetDBData());
                 m_xDatabaseTLB->Select(aTmp.sDataSource, aTmp.sCommand, u"");
@@ -197,15 +196,16 @@ bool SwFieldDBPage::FillItemSet(SfxItemSet* )
     aData.sDataSource = m_xDatabaseTLB->GetDBName(sTableName, sColumnName, 
&bIsTable);
     aData.sCommand = sTableName;
     aData.nCommandType = bIsTable ? 0 : 1;
-    SwWrtShell *pSh = CheckAndGetWrtShell();
-    assert(pSh);
 
-    SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager();
-    if (pDbManager)
-        pDbManager->CommitLastRegistrations();
+    if (SwWrtShell *pSh = CheckAndGetWrtShell())
+    {
+        SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager();
+        if (pDbManager)
+            pDbManager->CommitLastRegistrations();
 
-    if (aData.sDataSource.isEmpty())
-        aData = pSh->GetDBData();
+        if (aData.sDataSource.isEmpty())
+            aData = pSh->GetDBData();
+    }
 
     if(!aData.sDataSource.isEmpty())       // without database no new field 
command
     {
@@ -292,8 +292,6 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox)
     if (nOld == GetTypeSel())
         return;
 
-    SwWrtShell *pSh = CheckAndGetWrtShell();
-    assert(pSh);
     bool bCond = false, bSetNo = false, bFormat = false, bDBFormat = false;
     const SwFieldTypesEnum nTypeId = 
static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());
 
@@ -315,7 +313,8 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox)
         {
             if (auto *const pField = 
dynamic_cast<SwDBNameInfField*>(GetCurField()))
             {
-                aData = pField->GetDBData(pSh->GetDoc());
+                if(SwWrtShell *pSh = CheckAndGetWrtShell())
+                    aData = pField->GetDBData(pSh->GetDoc());
             }
         }
         m_xDatabaseTLB->Select(aData.sDataSource, aData.sCommand, sColumnName);
diff --git a/sw/source/ui/fldui/fldfunc.cxx b/sw/source/ui/fldui/fldfunc.cxx
index d4de4413fffb..e84dcda1e780 100644
--- a/sw/source/ui/fldui/fldfunc.cxx
+++ b/sw/source/ui/fldui/fldfunc.cxx
@@ -312,7 +312,7 @@ IMPL_LINK_NOARG(SwFieldFuncPage, TypeHdl, weld::TreeView&, 
void)
             m_xNameED->SetDropEnable(true);
             m_xValueFT->set_label(SwResId(STR_INSTEXT));
             SwWrtShell* pSh = GetActiveWrtShell();
-            if (!IsFieldEdit() && pSh )
+            if (!IsFieldEdit() && pSh)
                 m_xValueED->set_text(pSh->GetSelText());
             bName = bValue = true;
             m_xNameED->set_accessible_name(m_xNameFT->get_label());
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx
index b7a30d589196..ea8e41414d4a 100644
--- a/sw/source/ui/fldui/fldref.cxx
+++ b/sw/source/ui/fldui/fldref.cxx
@@ -198,7 +198,6 @@ void SwFieldRefPage::Reset(const SfxItemSet* )
     SwWrtShell *pSh = GetWrtShell();
     if (!pSh)
         pSh = ::GetActiveWrtShell();
-
     if (!pSh)
         return;
 
@@ -490,8 +489,11 @@ void SwFieldRefPage::SubTypeHdl()
 void SwFieldRefPage::UpdateSubType(const OUString& filterString)
 {
     SwWrtShell *pSh = GetWrtShell();
-    if(!pSh)
+    if (!pSh)
         pSh = ::GetActiveWrtShell();
+    if (!pSh)
+        return;
+
     SwGetRefField const*const 
pRefField(dynamic_cast<SwGetRefField*>(GetCurField()));
     const sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32();
 
@@ -980,13 +982,12 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* )
 
     SwGetRefField const*const 
pRefField(dynamic_cast<SwGetRefField*>(GetCurField()));
 
-    if (REFFLDFLAG & nTypeId)
+    SwWrtShell *pSh = GetWrtShell();
+    if(!pSh)
+        pSh = ::GetActiveWrtShell();
+
+    if (pSh && REFFLDFLAG & nTypeId)
     {
-        SwWrtShell *pSh = GetWrtShell();
-        if(!pSh)
-        {
-            pSh = ::GetActiveWrtShell();
-        }
         if (nTypeId == REFFLDFLAG_BOOKMARK)     // text marks!
         {
             aName = m_xNameED->get_text();
diff --git a/sw/source/ui/fmtui/tmpdlg.cxx b/sw/source/ui/fmtui/tmpdlg.cxx
index 8ebf75129db7..132296f83a9b 100644
--- a/sw/source/ui/fmtui/tmpdlg.cxx
+++ b/sw/source/ui/fmtui/tmpdlg.cxx
@@ -308,11 +308,14 @@ void SwTemplateDlgController::PageCreated(const OString& 
rId, SfxTabPage &rPage
         }
         else if (SfxStyleFamily::Pseudo == m_nType)
         {
-            SwDocShell* pDocShell = 
::GetActiveWrtShell()->GetView().GetDocShell();
-            FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( 
pDocShell) !=  nullptr );
+            if (SwWrtShell* pSh = ::GetActiveWrtShell())
+            {
+                SwDocShell* pDocShell = pSh->GetView().GetDocShell();
+                FieldUnit eMetric = 
::GetDfltMetric(dynamic_cast<SwWebDocShell*>( pDocShell) !=  nullptr );
 
-            aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 
>(eMetric)));
-            rPage.PageCreated(aSet);
+                aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< 
sal_uInt16 >(eMetric)));
+                rPage.PageCreated(aSet);
+            }
         }
     }
     else if (rId == "columns")
@@ -472,18 +475,21 @@ void SwTemplateDlgController::PageCreated(const OString& 
rId, SfxTabPage &rPage
         std::unique_ptr<weld::ComboBox> 
xCharFormatLB(xBuilder->weld_combo_box("combobox"));
         xCharFormatLB->clear();
         xCharFormatLB->append_text(SwViewShell::GetShellRes()->aStrNone);
-        SwDocShell* pDocShell = ::GetActiveWrtShell()->GetView().GetDocShell();
-        ::FillCharStyleListBox(*xCharFormatLB,  pDocShell);
+        if (SwWrtShell* pSh = ::GetActiveWrtShell())
+        {
+            SwDocShell* pDocShell = pSh->GetView().GetDocShell();
+            ::FillCharStyleListBox(*xCharFormatLB,  pDocShell);
 
-        std::vector<OUString> aList;
-        aList.reserve(xCharFormatLB->get_count());
-        for (sal_Int32 j = 0; j < xCharFormatLB->get_count(); j++)
-            aList.push_back(xCharFormatLB->get_text(j));
+            std::vector<OUString> aList;
+            aList.reserve(xCharFormatLB->get_count());
+            for (sal_Int32 j = 0; j < xCharFormatLB->get_count(); j++)
+                aList.push_back(xCharFormatLB->get_text(j));
 
-        aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ;
-        FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell 
*>( pDocShell ) !=  nullptr);
-        aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 
>(eMetric)));
-        rPage.PageCreated(aSet);
+            aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ;
+            FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const 
SwWebDocShell *>( pDocShell ) !=  nullptr);
+            aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 
>(eMetric)));
+            rPage.PageCreated(aSet);
+        }
     }
     else if (rId == "indents")
     {
diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx
index 2b8b9105caab..8dff4cd41e59 100644
--- a/sw/source/ui/frmdlg/frmpage.cxx
+++ b/sw/source/ui/frmdlg/frmpage.cxx
@@ -859,6 +859,9 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
 {
     SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() :
             getFrameDlgParentShell();
+    OSL_ENSURE(pSh , "shell not found");
+    if (!pSh)
+        return;
 
     m_nHtmlMode = ::GetHtmlMode(pSh->GetView().GetDocShell());
     m_bHtmlMode = (m_nHtmlMode & HTMLMODE_ON) != 0;
@@ -902,7 +905,6 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
 
     if ( m_sDlgType == "PictureDialog" || m_sDlgType == "ObjectDialog" )
     {
-        OSL_ENSURE(pSh , "shell not found");
         pSh->GetGrfSize( m_aGrfSize );
 
         if ( !m_bNew )
@@ -1031,9 +1033,7 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
 bool SwFramePage::FillItemSet(SfxItemSet *rSet)
 {
     bool bRet = false;
-    SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
-                        : getFrameDlgParentShell();
-    OSL_ENSURE( pSh , "shell not found");
+
     const SfxItemSet& rOldSet = GetItemSet();
     const SfxPoolItem* pOldItem = nullptr;
 
@@ -1044,8 +1044,14 @@ bool SwFramePage::FillItemSet(SfxItemSet *rSet)
         pOldItem = GetOldItem(*rSet, RES_ANCHOR);
         if (m_bNew || !pOldItem || eAnchorId != static_cast<const 
SwFormatAnchor*>(pOldItem)->GetAnchorId())
         {
-            SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() );
-            bRet = nullptr != rSet->Put( aAnc );
+            SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
+                                : getFrameDlgParentShell();
+            OSL_ENSURE( pSh , "shell not found");
+            if (pSh)
+            {
+                SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() );
+                bRet = nullptr != rSet->Put( aAnc );
+            }
         }
     }
 
@@ -1703,9 +1709,12 @@ DeactivateRC SwFramePage::DeactivatePage(SfxItemSet * 
_pSet)
             //the original. But for the other pages we need the current anchor.
             SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
                                 : getFrameDlgParentShell();
-            RndStdIds eAnchorId = GetAnchor();
-            SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() );
-            _pSet->Put( aAnc );
+            if (pSh)
+            {
+                RndStdIds eAnchorId = GetAnchor();
+                SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() );
+                _pSet->Put( aAnc );
+            }
         }
     }
 
@@ -1758,6 +1767,9 @@ void SwFramePage::RangeModifyHdl()
     SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell()
                         : getFrameDlgParentShell();
     OSL_ENSURE(pSh , "shell not found");
+    if (!pSh)
+        return;
+
     SwFlyFrameAttrMgr aMgr( m_bNew, pSh, GetItemSet() );
     SvxSwFrameValidation        aVal;
 
diff --git a/sw/source/ui/frmdlg/wrap.cxx b/sw/source/ui/frmdlg/wrap.cxx
index be60343e39b4..457fa346558b 100644
--- a/sw/source/ui/frmdlg/wrap.cxx
+++ b/sw/source/ui/frmdlg/wrap.cxx
@@ -379,9 +379,9 @@ void SwWrapTabPage::ActivatePage(const SfxItemSet& rSet)
     m_nAnchorId = rAnch.GetAnchorId();
     bool bEnable = (m_nAnchorId != RndStdIds::FLY_AS_CHAR);
 
-    if (!m_bDrawMode)
+    SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : m_pWrtSh;
+    if (pSh && !m_bDrawMode)
     {
-        SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : m_pWrtSh;
         SwFlyFrameAttrMgr aMgr( m_bNew, pSh, GetItemSet() );
         SvxSwFrameValidation aVal;
 
diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx
index 6e338564e124..99c9d811c52f 100644
--- a/sw/source/uibase/app/appopt.cxx
+++ b/sw/source/uibase/app/appopt.cxx
@@ -263,26 +263,28 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const 
SfxItemSet& rSet )
         pElemItem->FillViewOptions( aViewOpt );
 
         // Outline-folding options
-        SwWrtShell* pWrtShell = GetActiveWrtShell();
-        bool bIsOutlineFoldingOn = 
pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton();
-        bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent()
-                != 
pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent();
-        if (bIsOutlineFoldingOn &&
-                (!aViewOpt.IsShowOutlineContentVisibilityButton() || 
bTreatSubsChanged))
+        if (SwWrtShell* pWrtShell = GetActiveWrtShell())
         {
-            // Outline-folding options have change which require to show all 
content.
-            // Either outline-folding is being switched off or outline-folding 
is currently on
-            // and the treat subs option has changed.
-            
pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
-            if (bTreatSubsChanged)
-                bReFoldOutlineFolding = true; // folding method changed, set 
flag to refold below
-        }
-        else
-        {
-            // Refold needs to be done when outline-folding is being turned on 
or off
-            bReFoldOutlineFolding =
-                    
pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton() !=
-                    aViewOpt.IsShowOutlineContentVisibilityButton();
+            bool bIsOutlineFoldingOn = 
pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton();
+            bool bTreatSubsChanged = 
aViewOpt.IsTreatSubOutlineLevelsAsContent()
+                    != 
pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent();
+            if (bIsOutlineFoldingOn &&
+                    (!aViewOpt.IsShowOutlineContentVisibilityButton() || 
bTreatSubsChanged))
+            {
+                // Outline-folding options have change which require to show 
all content.
+                // Either outline-folding is being switched off or 
outline-folding is currently on
+                // and the treat subs option has changed.
+                
pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+                if (bTreatSubsChanged)
+                    bReFoldOutlineFolding = true; // folding method changed, 
set flag to refold below
+            }
+            else
+            {
+                // Refold needs to be done when outline-folding is being 
turned on or off
+                bReFoldOutlineFolding =
+                        
pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton() !=
+                        aViewOpt.IsShowOutlineContentVisibilityButton();
+            }
         }
     }
 
@@ -400,8 +402,11 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const 
SfxItemSet& rSet )
 
     if (bReFoldOutlineFolding)
     {
-        
GetActiveWrtShell()->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
-        
GetActiveWrtShell()->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+        if (SwWrtShell* pWrtShell = GetActiveWrtShell())
+        {
+            
pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+            
pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+        }
     }
 }
 
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 93acaa102692..1499f24098e6 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1419,11 +1419,14 @@ static void 
lcl_SetOutlineContentEntriesSensitivities(SwContentTree* pThis, cons
 
     bool bIsRoot = lcl_IsContentType(rEntry, rContentTree);
 
-    if 
(pThis->GetActiveWrtShell()->GetViewOptions()->IsTreatSubOutlineLevelsAsContent())
+    if (const SwWrtShell* pSh = pThis->GetActiveWrtShell())
     {
-        if (!bIsRoot)
-            
rPop.set_sensitive(OString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY), true);
-        return;
+        if (pSh->GetViewOptions()->IsTreatSubOutlineLevelsAsContent())
+        {
+            if (!bIsRoot)
+                
rPop.set_sensitive(OString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY), true);
+            return;
+        }
     }
 
     const SwNodes& rNodes = pThis->GetWrtShell()->GetNodes();
diff --git a/sw/source/uibase/utlui/glbltree.cxx 
b/sw/source/uibase/utlui/glbltree.cxx
index d6577271cc3b..caf4d12f8472 100644
--- a/sw/source/uibase/utlui/glbltree.cxx
+++ b/sw/source/uibase/utlui/glbltree.cxx
@@ -205,14 +205,17 @@ sal_Int8 SwGlobalTreeDropTarget::ExecuteDrop( const 
ExecuteDropEvent& rEvt )
                 // to not work on an old content.
                 if(n)
                 {
-                    
m_rTreeView.GetActiveWrtShell()->GetGlobalDocContent(aTempContents);
-                    // If the file was successfully inserted,
-                    // then the next content must also be fetched.
-                    if(nEntryCount < aTempContents.size())
+                    if (const SwWrtShell* pSh = 
m_rTreeView.GetActiveWrtShell())
                     {
-                        nEntryCount++;
-                        nAbsContPos++;
-                        pCnt = aTempContents[ nAbsContPos ].get();
+                        pSh->GetGlobalDocContent(aTempContents);
+                        // If the file was successfully inserted,
+                        // then the next content must also be fetched.
+                        if(nEntryCount < aTempContents.size())
+                        {
+                            nEntryCount++;
+                            nAbsContPos++;
+                            pCnt = aTempContents[ nAbsContPos ].get();
+                        }
                     }
                 }
             }
commit 3dd417b3b0ce2295df23135077ca074291744918
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Feb 16 16:24:58 2023 +0000
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:30 2023 +0100

    Resolves: tdf#151395 need to track tiff offset from start of stream
    
    when importing them from EPS
    
    Change-Id: Ia3ba2aa188f8dcee0ede6d43311c5dcdccb1eb25
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147124
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index a611810a9aec..0251f0bcd9c1 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -38,11 +38,13 @@ namespace
     struct Context
     {
         SvStream& rStream;
+        tsize_t nStart;
         tsize_t nSize;
         bool bAllowOneShortRead;
-        Context(SvStream& rInStream, tsize_t nInSize)
+        Context(SvStream& rInStream)
             : rStream(rInStream)
-            , nSize(nInSize)
+            , nStart(rInStream.Tell())
+            , nSize(rInStream.remainingSize())
             , bAllowOneShortRead(false)
         {
         }
@@ -76,9 +78,10 @@ static toff_t tiff_seek(thandle_t handle, toff_t offset, int 
whence)
     switch (whence)
     {
         case SEEK_SET:
+            offset = pContext->nStart + offset;
             break;
         case SEEK_CUR:
-            offset = pContext->rStream.Tell() + offset;;
+            offset = pContext->rStream.Tell() + offset;
             break;
         case SEEK_END:
             offset = pContext->rStream.TellEnd() + offset;
@@ -90,7 +93,7 @@ static toff_t tiff_seek(thandle_t handle, toff_t offset, int 
whence)
 
     pContext->rStream.Seek(offset);
 
-    return offset;
+    return offset - pContext->nStart;
 }
 
 static int tiff_close(thandle_t)
@@ -113,7 +116,7 @@ bool ImportTiffGraphicImport(SvStream& rTIFF, Graphic& 
rGraphic)
         TIFFSetWarningHandler(origWarningHandler);
     });
 
-    Context aContext(rTIFF, rTIFF.remainingSize());
+    Context aContext(rTIFF);
     TIFF* tif = TIFFClientOpen("libtiff-svstream", "r", &aContext,
                                tiff_read, tiff_write,
                                tiff_seek, tiff_close,
commit 1fe1f64d4ed9fa50de68413405ed6b17f9bac4c2
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Feb 16 20:36:57 2023 +0000
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:29 2023 +0100

    crashreporting: divide by zero, aPrefSize.Width() must have been 0 here
    
    Change-Id: I5ee2c1f4386c95c12fb821a3514cb732b220bb86
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147125
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/vcl/source/filter/png/PngImageWriter.cxx 
b/vcl/source/filter/png/PngImageWriter.cxx
index fd5ba3c84e8e..f550d9951e64 100644
--- a/vcl/source/filter/png/PngImageWriter.cxx
+++ b/vcl/source/filter/png/PngImageWriter.cxx
@@ -170,9 +170,12 @@ static bool pngWrite(SvStream& rStream, const BitmapEx& 
rBitmapEx, int nCompress
         if (aBitmapEx.GetPrefMapMode().GetMapUnit() == MapUnit::Map100thMM)
         {
             Size aPrefSize(aBitmapEx.GetPrefSize());
-            sal_uInt32 nPrefSizeX = o3tl::convert(aSize.Width(), 100000, 
aPrefSize.Width());
-            sal_uInt32 nPrefSizeY = o3tl::convert(aSize.Height(), 100000, 
aPrefSize.Height());
-            png_set_pHYs(pPng, pInfo, nPrefSizeX, nPrefSizeY, 1);
+            if (aPrefSize.Width() && aPrefSize.Height())
+            {
+                sal_uInt32 nPrefSizeX = o3tl::convert(aSize.Width(), 100000, 
aPrefSize.Width());
+                sal_uInt32 nPrefSizeY = o3tl::convert(aSize.Height(), 100000, 
aPrefSize.Height());
+                png_set_pHYs(pPng, pInfo, nPrefSizeX, nPrefSizeY, 1);
+            }
         }
 
         png_set_compression_level(pPng, nCompressionLevel);
commit 7e206a43d81b2f1b5bf7bae3c89d3c38d3ba35d8
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Thu Feb 16 20:20:31 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun Feb 19 22:48:29 2023 +0100

    Obtain actual 0-parameter count for OR(), AND() and 1-parameter functions
    
    OR and AND for legacy infix notation are classified as binary
    operators but in fact are functions with parameter count. In case
    no argument is supplied, GetByte() returns 0 and for that case the
    implicit binary operator 2 parameters were wrongly assumed.
    Similar for functions expecting 1 parameter, without argument 1
    was assumed. For "real" unary and binary operators the compiler
    already checks parameters. Omit OR and AND and 1-parameter
    functions from this implicit assumption and return the actual 0
    count.
    
    Change-Id: Ie05398c112a98021ac2875cf7b6de994aee9d882
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147173
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit e7ce9bddadb2db222eaa5f594ef1de2e36d57e5c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147128
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/formula/source/core/api/token.cxx 
b/formula/source/core/api/token.cxx
index ca7b7bab3d58..74a212937bb0 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -94,17 +94,14 @@ sal_uInt8 FormulaToken::GetParamCount() const
         return 0;       // parameters and specials
                         // ocIf... jump commands not for FAP, have cByte then
 //2do: bool parameter whether FAP or not?
-    else if ( GetByte() )
+    else if (GetByte())
         return GetByte();   // all functions, also ocExternal and ocMacro
-    else if (SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_BIN_OP)
-        return 2;           // binary
-    else if ((SC_OPCODE_START_UN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP)
-            || eOp == ocPercentSign)
-        return 1;           // unary
+    else if (SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_BIN_OP && 
eOp != ocAnd && eOp != ocOr)
+        return 2;           // binary operators, compiler checked; OR and AND 
legacy but are functions
+    else if ((SC_OPCODE_START_UN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP) || 
eOp == ocPercentSign)
+        return 1;           // unary operators, compiler checked
     else if (SC_OPCODE_START_NO_PAR <= eOp && eOp < SC_OPCODE_STOP_NO_PAR)
         return 0;           // no parameter
-    else if (SC_OPCODE_START_1_PAR <= eOp && eOp < SC_OPCODE_STOP_1_PAR)
-        return 1;           // one parameter
     else if (FormulaCompiler::IsOpCodeJumpCommand( eOp ))
         return 1;           // only the condition counts as parameter
     else
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index b122a836d654..1f14981ebadc 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4034,7 +4034,15 @@ StackVar ScInterpreter::Interpret()
                 else if (sp >= pCur->GetParamCount())
                     nStackBase = sp - pCur->GetParamCount();
                 else
-                    nStackBase = sp;    // underflow?!?
+                {
+                    SAL_WARN("sc.core", "Stack anomaly at " << aPos.Format(
+                                ScRefFlags::VALID | ScRefFlags::FORCE_DOC | 
ScRefFlags::TAB_3D, &mrDoc)
+                            << "  eOp: " << static_cast<int>(eOp)
+                            << "  params: " << 
static_cast<int>(pCur->GetParamCount())
+                            << "  nStackBase: " << nStackBase << "  sp: " << 
sp);
+                    nStackBase = sp;
+                    assert(!"underflow");
+                }
             }
 
             switch( eOp )

Reply via email to