tdf#143342: fix crash when using "Search Command" feature

Error: attempt to subscript container with out-of-bounds index -1, but
container only holds 0 elements.

Objects involved in the operation:
    sequence "this" @ 0x0x85b1d50 {
      type = std::__debug::vector<CurrentEntry, std::allocator<CurrentEntry> >;
    }

4  0x00007fe75d569357 in CommandListBox::RowActivated(weld::TreeView&) (this=0x85b1d30) at sfx2/source/commandpopup/CommandPopup.cxx:202
5  0x00007fe75d569649 in CommandListBox::TreeViewKeyPress(KeyEvent const&) (this=0x85b1d30, rKeyEvent=...) at sfx2/source/commandpopup/CommandPopup.cxx:222
6  0x00007fe75d569170 in CommandListBox::LinkStubTreeViewKeyPress(void*, KeyEvent const&) (instance=0x85b1d30, data=...) at sfx2/source/commandpopup/CommandPopup.cxx:209

Change-Id: I62923ce106da62e3d7d7572536f5e065773683ea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118891
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
Julien Nabet 2021-07-14 11:39:07 +02:00
parent 2575f97571
commit 32b820b7ac

View file

@ -197,7 +197,7 @@ IMPL_LINK_NOARG(CommandListBox, RowActivated, weld::TreeView&, bool)
{
OUString aCommandURL;
int nSelected = mpCommandTreeView->get_selected_index();
if (nSelected < int(maCommandList.size()))
if (nSelected != -1 && nSelected < int(maCommandList.size()))
{
auto const& rCurrent = maCommandList[nSelected];
aCommandURL = rCurrent.m_aCommandURL;