[Libreoffice-commits] core.git: 3 commits - sd/source

Caolán McNamara caolanm at redhat.com
Sat Jul 15 14:35:26 UTC 2017


 sd/source/ui/sidebar/SlideBackground.cxx |   16 +-
 sd/source/ui/view/drviews7.cxx           |  202 +++++++++++++++----------------
 2 files changed, 110 insertions(+), 108 deletions(-)

New commits:
commit fe2dfdba10a0b54bd915a4186a0347672c61fcec
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Jul 15 15:02:38 2017 +0100

    improve variable scope
    
    Change-Id: I1207c570c4bceac73b3197e11bcefcf73837d1b3

diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
index b95669665172..97a595cc1abc 100644
--- a/sd/source/ui/view/drviews7.cxx
+++ b/sd/source/ui/view/drviews7.cxx
@@ -1756,133 +1756,132 @@ void DrawViewShell::GetPageProperties( SfxItemSet &rSet )
 void DrawViewShell::SetPageProperties (SfxRequest& rReq)
 {
     SdPage *pPage = getCurrentPage();
+    if (!pPage)
+        return;
     sal_uInt16 nSlotId = rReq.GetSlot();
     const SfxItemSet *pArgs = rReq.GetArgs();
+    if (!pArgs)
+        return;
 
-    if ( pPage && pArgs )
+    if ( ( nSlotId >= SID_ATTR_PAGE_COLOR ) && ( nSlotId <= SID_ATTR_PAGE_FILLSTYLE ) )
     {
-        Size aSize = pPage->GetSize();
-        PageKind ePageKind = GetPageKind();
-        const SfxPoolItem*  pPoolItem = nullptr;
-        Size                aNewSize(aSize);
-        sal_Int32           nLeft  = -1, nRight = -1, nUpper = -1, nLower = -1;
-        bool                bScaleAll = true;
-        Orientation         eOrientation = pPage->GetOrientation();
-        SdPage*             pMasterPage = pPage->IsMasterPage() ? pPage : &static_cast<SdPage&>(pPage->TRG_GetMasterPage());
-        bool                bFullSize = pMasterPage->IsBackgroundFullSize();
-        sal_uInt16          nPaperBin = pPage->GetPaperBin();
+        SdrPageProperties& rPageProperties = pPage->getSdrPageProperties();
+        const SfxItemSet &aPageItemSet = rPageProperties.GetItemSet();
+        SfxItemSet *pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool());
+
+        rPageProperties.ClearItem(XATTR_FILLSTYLE);
+        rPageProperties.ClearItem(XATTR_FILLGRADIENT);
+        rPageProperties.ClearItem(XATTR_FILLHATCH);
+        rPageProperties.ClearItem(XATTR_FILLBITMAP);
 
-        if ( ( nSlotId >= SID_ATTR_PAGE_COLOR ) && ( nSlotId <= SID_ATTR_PAGE_FILLSTYLE ) )
+        switch (nSlotId)
         {
-            SdrPageProperties& rPageProperties = pPage->getSdrPageProperties();
-            const SfxItemSet &aPageItemSet = rPageProperties.GetItemSet();
-            SfxItemSet *pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool());
+            case(SID_ATTR_PAGE_FILLSTYLE):
+            {
+                XFillStyleItem aFSItem( static_cast<const XFillStyleItem&>(pArgs->Get( XATTR_FILLSTYLE )) );
+                drawing::FillStyle eXFS = aFSItem.GetValue();
 
-            rPageProperties.ClearItem(XATTR_FILLSTYLE);
-            rPageProperties.ClearItem(XATTR_FILLGRADIENT);
-            rPageProperties.ClearItem(XATTR_FILLHATCH);
-            rPageProperties.ClearItem(XATTR_FILLBITMAP);
+                if ( eXFS == drawing::FillStyle_NONE )
+                     rPageProperties.PutItem( XFillStyleItem( eXFS ) );
+            }
+            break;
 
-            switch (nSlotId)
+            case(SID_ATTR_PAGE_COLOR):
             {
-                case(SID_ATTR_PAGE_FILLSTYLE):
-                {
-                    XFillStyleItem aFSItem( static_cast<const XFillStyleItem&>(pArgs->Get( XATTR_FILLSTYLE )) );
-                    drawing::FillStyle eXFS = aFSItem.GetValue();
-
-                    if ( eXFS == drawing::FillStyle_NONE )
-                         rPageProperties.PutItem( XFillStyleItem( eXFS ) );
-                }
-                break;
+                XFillColorItem aColorItem( static_cast<const XFillColorItem&>(pArgs->Get( XATTR_FILLCOLOR )) );
+                rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_SOLID ) );
+                rPageProperties.PutItem( aColorItem );
+            }
+            break;
 
-                case(SID_ATTR_PAGE_COLOR):
-                {
-                    XFillColorItem aColorItem( static_cast<const XFillColorItem&>(pArgs->Get( XATTR_FILLCOLOR )) );
-                    rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_SOLID ) );
-                    rPageProperties.PutItem( aColorItem );
-                }
-                break;
+            case(SID_ATTR_PAGE_GRADIENT):
+            {
+                XFillGradientItem aGradientItem( static_cast<const XFillGradientItem&>(pArgs->Get( XATTR_FILLGRADIENT )) );
 
-                case(SID_ATTR_PAGE_GRADIENT):
-                {
-                    XFillGradientItem aGradientItem( static_cast<const XFillGradientItem&>(pArgs->Get( XATTR_FILLGRADIENT )) );
+                // MigrateItemSet guarantees unique gradient names
+                SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT>{} );
+                aMigrateSet.Put( aGradientItem );
+                SdrModel::MigrateItemSet( &aMigrateSet, pTempSet, mpDrawView->GetModel() );
 
-                    // MigrateItemSet guarantees unique gradient names
-                    SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT>{} );
-                    aMigrateSet.Put( aGradientItem );
-                    SdrModel::MigrateItemSet( &aMigrateSet, pTempSet, mpDrawView->GetModel() );
+                rPageProperties.PutItemSet( *pTempSet );
+                rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
+            }
+            break;
 
-                    rPageProperties.PutItemSet( *pTempSet );
-                    rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
-                }
-                break;
+            case(SID_ATTR_PAGE_HATCH):
+            {
+                XFillHatchItem aHatchItem( static_cast<const XFillHatchItem&>(pArgs->Get( XATTR_FILLHATCH )) );
+                rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_HATCH ) );
+                rPageProperties.PutItem( aHatchItem );
+            }
+            break;
 
-                case(SID_ATTR_PAGE_HATCH):
-                {
-                    XFillHatchItem aHatchItem( static_cast<const XFillHatchItem&>(pArgs->Get( XATTR_FILLHATCH )) );
-                    rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_HATCH ) );
-                    rPageProperties.PutItem( aHatchItem );
-                }
-                break;
+            case(SID_ATTR_PAGE_BITMAP):
+            {
+                XFillBitmapItem aBitmapItem( static_cast<const XFillBitmapItem&>(pArgs->Get( XATTR_FILLBITMAP )) );
+                rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_BITMAP ) );
+                rPageProperties.PutItem( aBitmapItem );
+            }
+            break;
 
-                case(SID_ATTR_PAGE_BITMAP):
-                {
-                    XFillBitmapItem aBitmapItem( static_cast<const XFillBitmapItem&>(pArgs->Get( XATTR_FILLBITMAP )) );
-                    rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_BITMAP ) );
-                    rPageProperties.PutItem( aBitmapItem );
-                }
-                break;
+            default:
+            break;
+        }
 
-                default:
-                break;
-            }
+        delete pTempSet;
 
-            delete pTempSet;
+        rReq.Done();
+    }
+    else
+    {
+        PageKind            ePageKind = GetPageKind();
+        const SfxPoolItem*  pPoolItem = nullptr;
+        Size                aNewSize(pPage->GetSize());
+        sal_Int32           nLeft  = -1, nRight = -1, nUpper = -1, nLower = -1;
+        bool                bScaleAll = true;
+        Orientation         eOrientation = pPage->GetOrientation();
+        SdPage*             pMasterPage = pPage->IsMasterPage() ? pPage : &static_cast<SdPage&>(pPage->TRG_GetMasterPage());
+        bool                bFullSize = pMasterPage->IsBackgroundFullSize();
+        sal_uInt16          nPaperBin = pPage->GetPaperBin();
 
-            rReq.Done();
-        }
-        else
+        switch (nSlotId)
         {
-            switch (nSlotId)
-            {
-                case SID_ATTR_PAGE_LRSPACE:
-                    if( pArgs->GetItemState(GetPool().GetWhich(SID_ATTR_PAGE_LRSPACE),
-                                            true,&pPoolItem) == SfxItemState::SET )
+            case SID_ATTR_PAGE_LRSPACE:
+                if( pArgs->GetItemState(GetPool().GetWhich(SID_ATTR_PAGE_LRSPACE),
+                                        true,&pPoolItem) == SfxItemState::SET )
+                {
+                    nLeft = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetLeft();
+                    nRight = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetRight();
+                    if (nLeft != -1 && nUpper == -1)
                     {
-                        nLeft = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetLeft();
-                        nRight = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetRight();
-                        if (nLeft != -1 && nUpper == -1)
-                        {
-                            nUpper  = pPage->GetUppBorder();
-                            nLower  = pPage->GetLwrBorder();
-                        }
-                        SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
+                        nUpper  = pPage->GetUppBorder();
+                        nLower  = pPage->GetLwrBorder();
                     }
-                    break;
+                    SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
+                }
+                break;
 
-                case SID_ATTR_PAGE_ULSPACE:
-                    if( pArgs->GetItemState(SID_ATTR_PAGE_ULSPACE,
-                                            true,&pPoolItem) == SfxItemState::SET )
+            case SID_ATTR_PAGE_ULSPACE:
+                if( pArgs->GetItemState(SID_ATTR_PAGE_ULSPACE,
+                                        true,&pPoolItem) == SfxItemState::SET )
+                {
+                    nUpper = static_cast<const SvxLongULSpaceItem*>(pPoolItem)->GetUpper();
+                    nLower = static_cast<const SvxLongULSpaceItem*>(pPoolItem)->GetLower();
+                    if (nLeft == -1 && nUpper != -1)
                     {
-                        nUpper = static_cast<const SvxLongULSpaceItem*>(pPoolItem)->GetUpper();
-                        nLower = static_cast<const SvxLongULSpaceItem*>(pPoolItem)->GetLower();
-                        if (nLeft == -1 && nUpper != -1)
-                        {
-                            nLeft   = pPage->GetLftBorder();
-                            nRight  = pPage->GetRgtBorder();
-                        }
-                        SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
+                        nLeft   = pPage->GetLftBorder();
+                        nRight  = pPage->GetRgtBorder();
                     }
-                    break;
-
-                default:
+                    SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
+                }
                 break;
-            }
+
+            default:
+            break;
         }
     }
 }
 
-
 void DrawViewShell::GetState (SfxItemSet& rSet)
 {
     // Iterate over all requested items in the set.
commit cbf34897f067e0164f85c626650a8f2dc4f998b0
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Jul 15 14:58:11 2017 +0100

    coverity#1415091 Dereference before null check
    
    Change-Id: If22c6a9d9b312e52b2956fd84618d3e95fda1c3e

diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
index 3feab2fe0b0e..b95669665172 100644
--- a/sd/source/ui/view/drviews7.cxx
+++ b/sd/source/ui/view/drviews7.cxx
@@ -1758,21 +1758,20 @@ void DrawViewShell::SetPageProperties (SfxRequest& rReq)
     SdPage *pPage = getCurrentPage();
     sal_uInt16 nSlotId = rReq.GetSlot();
     const SfxItemSet *pArgs = rReq.GetArgs();
-    // const size_t nDescId    = rSh->GetCurPageDesc();
-    // const SdPage& rDesc = rSh->GetPageDesc( nDescId );
-    Size maSize = pPage->GetSize();
-    PageKind ePageKind = GetPageKind();
-    const SfxPoolItem*  pPoolItem = nullptr;
-    Size                aNewSize(maSize);
-    sal_Int32               nLeft  = -1, nRight = -1, nUpper = -1, nLower = -1;
-    bool                bScaleAll = true;
-    Orientation         eOrientation = pPage->GetOrientation();
-    SdPage*             pMasterPage = pPage->IsMasterPage() ? pPage : &static_cast<SdPage&>(pPage->TRG_GetMasterPage());
-    bool                bFullSize = pMasterPage->IsBackgroundFullSize();
-    sal_uInt16          nPaperBin = pPage->GetPaperBin();
 
     if ( pPage && pArgs )
     {
+        Size aSize = pPage->GetSize();
+        PageKind ePageKind = GetPageKind();
+        const SfxPoolItem*  pPoolItem = nullptr;
+        Size                aNewSize(aSize);
+        sal_Int32           nLeft  = -1, nRight = -1, nUpper = -1, nLower = -1;
+        bool                bScaleAll = true;
+        Orientation         eOrientation = pPage->GetOrientation();
+        SdPage*             pMasterPage = pPage->IsMasterPage() ? pPage : &static_cast<SdPage&>(pPage->TRG_GetMasterPage());
+        bool                bFullSize = pMasterPage->IsBackgroundFullSize();
+        sal_uInt16          nPaperBin = pPage->GetPaperBin();
+
         if ( ( nSlotId >= SID_ATTR_PAGE_COLOR ) && ( nSlotId <= SID_ATTR_PAGE_FILLSTYLE ) )
         {
             SdrPageProperties& rPageProperties = pPage->getSdrPageProperties();
commit 33ecb72fd52050687f74828263526a8e836c3bdf
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Jul 15 14:49:48 2017 +0100

    coverity#1415090 Unchecked dynamic_cast
    
    and
    
    coverity#1415096 Unchecked dynamic_cast
    
    Change-Id: I29a20a0868f8720a7aee60ebd6f55a7dbb76f894

diff --git a/sd/source/ui/sidebar/SlideBackground.cxx b/sd/source/ui/sidebar/SlideBackground.cxx
index 5011f7a58c01..a0c2e756e42c 100644
--- a/sd/source/ui/sidebar/SlideBackground.cxx
+++ b/sd/source/ui/sidebar/SlideBackground.cxx
@@ -733,7 +733,7 @@ void SlideBackground::NotifyItemUpdate(
         {
             const SvxSizeItem* pSizeItem = nullptr;
             if (eState >= SfxItemState::DEFAULT)
-                pSizeItem = dynamic_cast< const SvxSizeItem* >(pState);
+                pSizeItem = dynamic_cast<const SvxSizeItem*>(pState);
             if (pSizeItem)
             {
                 Size aPaperSize = pSizeItem->GetSize();
@@ -748,10 +748,12 @@ void SlideBackground::NotifyItemUpdate(
 
         case SID_ATTR_PAGE:
         {
-            if (eState >= SfxItemState::DEFAULT &&
-                pState && dynamic_cast< const SvxPageItem *>( pState ) !=  nullptr)
+            const SvxPageItem* pPageItem = nullptr;
+            if (eState >= SfxItemState::DEFAULT)
+                pPageItem = dynamic_cast<const SvxPageItem*>(pState);
+            if (pPageItem)
             {
-                mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) );
+                mpPageItem.reset(static_cast<SvxPageItem*>(pPageItem->Clone()));
                 bool bIsLandscape = mpPageItem->IsLandscape();
                 mpPaperOrientation->SelectEntryPos( bIsLandscape ? 0 : 1 );
             }
@@ -762,8 +764,9 @@ void SlideBackground::NotifyItemUpdate(
         {
             const SvxLongLRSpaceItem* pLRItem = nullptr;
             if (eState >= SfxItemState::DEFAULT)
-            {
                 pLRItem = dynamic_cast<const SvxLongLRSpaceItem*>(pState);
+            if (pLRItem)
+            {
                 m_nPageLeftMargin = pLRItem->GetLeft();
                 m_nPageRightMargin = pLRItem->GetRight();
                 SetFieldUnit(*m_pLeftMarginEdit, meFieldUnit, true);
@@ -778,8 +781,9 @@ void SlideBackground::NotifyItemUpdate(
         {
             const SvxLongULSpaceItem* pULItem = nullptr;
             if (eState >= SfxItemState::DEFAULT)
-            {
                 pULItem = dynamic_cast<const SvxLongULSpaceItem*>(pState);
+            if (pULItem)
+            {
                 m_nPageTopMargin = pULItem->GetUpper();
                 m_nPageBottomMargin = pULItem->GetLower();
                 SetFieldUnit(*m_pTopMarginEdit, meFieldUnit, true);


More information about the Libreoffice-commits mailing list