1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-05 04:25:19 +02:00

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.
This commit is contained in:
Maarten ter Huurne 2015-04-22 09:39:44 +02:00
parent 1a5da1fd94
commit 3db955c471

View File

@ -346,10 +346,10 @@ void Menu::freeLinks() {
} }
vector<Link*> *Menu::sectionLinks(int i) { vector<Link*> *Menu::sectionLinks(int i) {
if (i<0 || i>(int)links.size()) if (i<0 || i>=(int)links.size())
i = selSectionIndex(); i = selSectionIndex();
if (i<0 || i>(int)links.size()) if (i<0 || i>=(int)links.size())
return NULL; return NULL;
return &links[i]; return &links[i];
@ -625,6 +625,11 @@ LinkApp *Menu::selLinkApp() {
} }
void Menu::setLinkIndex(int i) { void Menu::setLinkIndex(int i) {
auto links = sectionLinks();
if (!links) {
// No sections.
return;
}
const int numLinks = static_cast<int>(sectionLinks()->size()); const int numLinks = static_cast<int>(sectionLinks()->size());
if (i < 0) if (i < 0)
i = numLinks - 1; i = numLinks - 1;