diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-10-18 11:10:52 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-10-18 15:37:59 +0200 |
commit | ed4c5e3beb251e0ee13ad982ee7c512196c9923b (patch) | |
tree | 89aa7d824cc28c6215d214c503391eb400a25f6c | |
parent | af801eafd6b973dcd9e333898782ba43478a41d1 (diff) |
tdf#163486: PVS: check GetMenu()
V595 The 'GetMenu()' pointer was utilized before it was verified against nullptr. Check lines: 1582, 1612.
Change-Id: I085320d3a5467e4e2c158bf2683b3156cb103e8b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175125
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
-rw-r--r-- | include/vcl/toolbox.hxx | 2 | ||||
-rw-r--r-- | vcl/source/window/toolbox2.cxx | 26 |
2 files changed, 15 insertions, 13 deletions
diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx index b4b7922ac6a1..779c5853f0b7 100644 --- a/include/vcl/toolbox.hxx +++ b/include/vcl/toolbox.hxx @@ -474,7 +474,7 @@ public: ToolBoxMenuType GetMenuType() const; SAL_DLLPRIVATE bool IsMenuEnabled() const; PopupMenu* GetMenu() const; - SAL_DLLPRIVATE void UpdateCustomMenu(); + SAL_DLLPRIVATE void UpdateCustomMenu(PopupMenu* pMenu); void SetMenuExecuteHdl( const Link<ToolBox *, void>& rLink ); // open custommenu diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 8460dcf680c1..c0c806038060 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -1482,7 +1482,7 @@ bool ToolBox::IsMenuEnabled() const PopupMenu* ToolBox::GetMenu() const { - return mpData == nullptr ? nullptr : mpData->mpMenu; + return mpData ? mpData->mpMenu : nullptr; } void ToolBox::SetMenuExecuteHdl( const Link<ToolBox *, void>& rLink ) @@ -1512,10 +1512,9 @@ namespace } } -void ToolBox::UpdateCustomMenu() +void ToolBox::UpdateCustomMenu(PopupMenu* pMenu) { // fill clipped items into menu - PopupMenu *pMenu = GetMenu(); pMenu->Clear(); // add menu items: first the overflow items, then hidden items, both in the @@ -1560,9 +1559,10 @@ void ToolBox::UpdateCustomMenu() IMPL_LINK( ToolBox, ImplCustomMenuListener, VclMenuEvent&, rEvent, void ) { - if( rEvent.GetMenu() == GetMenu() && rEvent.GetId() == VclEventId::MenuSelect ) + PopupMenu *pMenu = GetMenu(); + if( pMenu && rEvent.GetMenu() == pMenu && rEvent.GetId() == VclEventId::MenuSelect ) { - sal_uInt16 id = GetMenu()->GetItemId( rEvent.GetItemPos() ); + sal_uInt16 id = pMenu->GetItemId( rEvent.GetItemPos() ); if( id >= TOOLBOX_MENUITEM_START ) TriggerItem( ToolBoxItemId(id - TOOLBOX_MENUITEM_START) ); } @@ -1573,17 +1573,20 @@ void ToolBox::ExecuteCustomMenu( const tools::Rectangle& rRect ) if ( !IsMenuEnabled() || ImplIsInPopupMode() ) return; - UpdateCustomMenu(); + PopupMenu *pMenu = GetMenu(); + if (!pMenu) + return; + UpdateCustomMenu(pMenu); if( GetMenuType() & ToolBoxMenuType::Customize ) // call button handler to allow for menu customization mpData->maMenuButtonHdl.Call( this ); - GetMenu()->AddEventListener( LINK( this, ToolBox, ImplCustomMenuListener ) ); + pMenu->AddEventListener( LINK( this, ToolBox, ImplCustomMenuListener ) ); // make sure all disabled entries will be shown - GetMenu()->SetMenuFlags( - GetMenu()->GetMenuFlags() | MenuFlags::AlwaysShowDisabledEntries ); + pMenu->SetMenuFlags( + pMenu->GetMenuFlags() | MenuFlags::AlwaysShowDisabledEntries ); // toolbox might be destroyed during execute bool bBorderDel = false; @@ -1603,14 +1606,13 @@ void ToolBox::ExecuteCustomMenu( const tools::Rectangle& rRect ) } } - sal_uInt16 uId = GetMenu()->Execute( pWin, tools::Rectangle( ImplGetPopupPosition( aMenuRect ), Size() ), + sal_uInt16 uId = pMenu->Execute( pWin, tools::Rectangle( ImplGetPopupPosition( aMenuRect ), Size() ), PopupMenuFlags::ExecuteDown | PopupMenuFlags::NoMouseUpClose ); if ( pWin->isDisposed() ) return; - if( GetMenu() ) - GetMenu()->RemoveEventListener( LINK( this, ToolBox, ImplCustomMenuListener ) ); + pMenu->RemoveEventListener( LINK( this, ToolBox, ImplCustomMenuListener ) ); if( bBorderDel ) { if( pBorderWin->isDisposed() ) |