include/vcl/toolbox.hxx | 2 +- vcl/source/window/toolbox2.cxx | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-)
New commits: commit 1ebff884cb1261d48130ea80fffc5bc0025a63df Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Oct 18 11:10:52 2024 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Mon Nov 4 14:48:54 2024 +0100 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 <xiscofa...@libreoffice.org> Tested-by: Jenkins (cherry picked from commit ed4c5e3beb251e0ee13ad982ee7c512196c9923b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175142 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> 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() )