From 3db955c471799c2a7b482091a8c37221f0b31369 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 22 Apr 2015 09:39:44 +0200 Subject: [PATCH] Avoid crash on startup when no applications are found The code cannot deal with there being no sections. After startup, there will always be sections for the built-in actions. But before those are added the lack of sections could be fatal. --- src/menu.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index 6953f5d..be70d17 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -346,10 +346,10 @@ void Menu::freeLinks() { } vector *Menu::sectionLinks(int i) { - if (i<0 || i>(int)links.size()) + if (i<0 || i>=(int)links.size()) i = selSectionIndex(); - if (i<0 || i>(int)links.size()) + if (i<0 || i>=(int)links.size()) return NULL; return &links[i]; @@ -625,6 +625,11 @@ LinkApp *Menu::selLinkApp() { } void Menu::setLinkIndex(int i) { + auto links = sectionLinks(); + if (!links) { + // No sections. + return; + } const int numLinks = static_cast(sectionLinks()->size()); if (i < 0) i = numLinks - 1;