From b15175b05bebd863371a3eb6d4836ab9afa5f9ec Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 12 Aug 2014 06:42:58 +0200 Subject: [PATCH] Require valid section index passed to Menu::addActionLink All calls to this method are in GMenu2X::initMenu() and they will only pass valid indices, so the range check was redundant. Also the return value was never used. Added an assert to spot any invalid indices from future code. --- src/menu.cpp | 8 ++++---- src/menu.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index dc41f69..f094201 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef HAVE_LIBOPK #include @@ -396,8 +397,8 @@ void Menu::setSectionIndex(int i) { /*==================================== LINKS MANAGEMENT ====================================*/ -bool Menu::addActionLink(uint section, const string &title, function_t action, const string &description, const string &icon) { - if (section>=sections.size()) return false; +void Menu::addActionLink(uint section, const string &title, function_t action, const string &description, const string &icon) { + assert(section < sections.size()); Link *link = new Link(gmenu2x, action); link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); @@ -410,8 +411,7 @@ bool Menu::addActionLink(uint section, const string &title, function_t action, c link->setIcon(icon); } - sectionLinks(section)->push_back(link); - return true; + links[section].push_back(link); } bool Menu::addLink(string path, string file, string section) { diff --git a/src/menu.h b/src/menu.h index 6fd9516..c668cbc 100644 --- a/src/menu.h +++ b/src/menu.h @@ -113,7 +113,7 @@ public: const std::string &selSection(); void setSectionIndex(int i); - bool addActionLink(uint section, const std::string &title, + void addActionLink(uint section, const std::string &title, function_t action, const std::string &description="", const std::string &icon=""); bool addLink(std::string path, std::string file, std::string section="");