sw/source/core/inc/frmtool.hxx | 2 +- sw/source/core/layout/frmtool.cxx | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-)
New commits: commit a30e2862c2bf4635c53a627659905de29934799b Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Aug 16 12:15:00 2022 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Aug 17 09:52:26 2022 +0200 cid#1500382 Dereference before null check Change-Id: I93f50bf404af29147294a5824dcdd3f12c983758 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138391 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx index c7177379a88e..d7c8e8249b7c 100644 --- a/sw/source/core/inc/frmtool.hxx +++ b/sw/source/core/inc/frmtool.hxx @@ -310,7 +310,7 @@ class SwBorderAttrs final : public SwCacheObj const SwAttrSet &m_rAttrSet; const SvxULSpaceItem &m_rUL; // #i96772# - std::shared_ptr<SvxLRSpaceItem> m_rLR; + std::shared_ptr<SvxLRSpaceItem> m_xLR; const SvxBoxItem &m_rBox; const SvxShadowItem &m_rShadow; const Size m_aFrameSize; diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx index 6bccf8d73869..cb16a9f59deb 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -2227,7 +2227,7 @@ SwBorderAttrs::SwBorderAttrs(const sw::BorderCacheOwner* pOwner, const SwFrame* , m_rUL(m_rAttrSet.GetULSpace()) // #i96772# // LRSpaceItem is copied due to the possibility that it is adjusted - see below - , m_rLR(m_rAttrSet.GetLRSpace().Clone()) + , m_xLR(m_rAttrSet.GetLRSpace().Clone()) , m_rBox(m_rAttrSet.GetBox()) , m_rShadow(m_rAttrSet.GetShadow()) , m_aFrameSize(m_rAttrSet.GetFrameSize().GetSize()) @@ -2248,13 +2248,15 @@ SwBorderAttrs::SwBorderAttrs(const sw::BorderCacheOwner* pOwner, const SwFrame* const SwTextFrame* pTextFrame = pConstructor->DynCastTextFrame(); if ( pTextFrame ) { - pTextFrame->GetTextNodeForParaProps()->ClearLRSpaceItemDueToListLevelIndents( m_rLR ); + pTextFrame->GetTextNodeForParaProps()->ClearLRSpaceItemDueToListLevelIndents( m_xLR ); } else if ( pConstructor->IsNoTextFrame() ) { - m_rLR = std::make_shared<SvxLRSpaceItem>(RES_LR_SPACE); + m_xLR = std::make_shared<SvxLRSpaceItem>(RES_LR_SPACE); } + assert(m_xLR && "always exists"); + // Caution: The USHORTs for the cached values are not initialized by intention! // everything needs to be calculated at least once: @@ -2285,15 +2287,12 @@ void SwBorderAttrs::CalcTop_() { m_nTop = CalcTopLine() + m_rUL.GetUpper(); - if (m_rLR) + bool bGutterAtTop = m_rAttrSet.GetDoc()->getIDocumentSettingAccess().get( + DocumentSettingId::GUTTER_AT_TOP); + if (bGutterAtTop) { - bool bGutterAtTop = m_rAttrSet.GetDoc()->getIDocumentSettingAccess().get( - DocumentSettingId::GUTTER_AT_TOP); - if (bGutterAtTop) - { - // Decrease the print area: the top space is the sum of top and gutter margins. - m_nTop += m_rLR->GetGutterMargin(); - } + // Decrease the print area: the top space is the sum of top and gutter margins. + m_nTop += m_xLR->GetGutterMargin(); } m_bTop = false; @@ -2320,9 +2319,9 @@ tools::Long SwBorderAttrs::CalcRight( const SwFrame* pCaller ) const } // for paragraphs, "left" is "before text" and "right" is "after text" if ( pCaller->IsTextFrame() && pCaller->IsRightToLeft() ) - nRight += m_rLR->GetLeft(); + nRight += m_xLR->GetLeft(); else - nRight += m_rLR->GetRight(); + nRight += m_xLR->GetRight(); // correction: retrieve left margin for numbering in R2L-layout if ( pCaller->IsTextFrame() && pCaller->IsRightToLeft() ) @@ -2330,7 +2329,7 @@ tools::Long SwBorderAttrs::CalcRight( const SwFrame* pCaller ) const nRight += static_cast<const SwTextFrame*>(pCaller)->GetTextNodeForParaProps()->GetLeftMarginWithNum(); } - if (pCaller->IsPageFrame() && m_rLR) + if (pCaller->IsPageFrame()) { const auto pPageFrame = static_cast<const SwPageFrame*>(pCaller); bool bGutterAtTop = pPageFrame->GetFormat()->getIDocumentSettingAccess().get( @@ -2338,7 +2337,7 @@ tools::Long SwBorderAttrs::CalcRight( const SwFrame* pCaller ) const if (!bGutterAtTop) { bool bRtlGutter = pPageFrame->GetAttrSet()->GetItem<SfxBoolItem>(RES_RTL_GUTTER)->GetValue(); - tools::Long nGutterMargin = bRtlGutter ? m_rLR->GetGutterMargin() : m_rLR->GetRightGutterMargin(); + tools::Long nGutterMargin = bRtlGutter ? m_xLR->GetGutterMargin() : m_xLR->GetRightGutterMargin(); // Decrease the print area: the right space is the sum of right and right gutter // margins. nRight += nGutterMargin; @@ -2383,7 +2382,7 @@ tools::Long SwBorderAttrs::CalcLeft( const SwFrame *pCaller ) const // for paragraphs, "left" is "before text" and "right" is "after text" if ( pCaller->IsTextFrame() && pCaller->IsRightToLeft() ) - nLeft += m_rLR->GetRight(); + nLeft += m_xLR->GetRight(); else { bool bIgnoreMargin = false; @@ -2401,7 +2400,7 @@ tools::Long SwBorderAttrs::CalcLeft( const SwFrame *pCaller ) const } } if (!bIgnoreMargin) - nLeft += m_rLR->GetLeft(); + nLeft += m_xLR->GetLeft(); } // correction: do not retrieve left margin for numbering in R2L-layout @@ -2410,7 +2409,7 @@ tools::Long SwBorderAttrs::CalcLeft( const SwFrame *pCaller ) const nLeft += static_cast<const SwTextFrame*>(pCaller)->GetTextNodeForParaProps()->GetLeftMarginWithNum(); } - if (pCaller->IsPageFrame() && m_rLR) + if (pCaller->IsPageFrame()) { const auto pPageFrame = static_cast<const SwPageFrame*>(pCaller); bool bGutterAtTop = pPageFrame->GetFormat()->getIDocumentSettingAccess().get( @@ -2418,7 +2417,7 @@ tools::Long SwBorderAttrs::CalcLeft( const SwFrame *pCaller ) const if (!bGutterAtTop) { bool bRtlGutter = pPageFrame->GetAttrSet()->GetItem<SfxBoolItem>(RES_RTL_GUTTER)->GetValue(); - tools::Long nGutterMargin = bRtlGutter ? m_rLR->GetRightGutterMargin() : m_rLR->GetGutterMargin(); + tools::Long nGutterMargin = bRtlGutter ? m_xLR->GetRightGutterMargin() : m_xLR->GetGutterMargin(); // Decrease the print area: the left space is the sum of left and gutter margins. nLeft += nGutterMargin; }