From 16218ae90b2499773d0c49a8c2900f269f5a2974 Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 8 Sep 2007 18:38:30 +0000 Subject: fix crash when changing toolbar visibility with empty toolbar.tools --- ChangeLog | 3 +++ src/FbTk/Menu.cc | 2 +- src/FbTk/MenuItem.cc | 7 +++++-- src/FbTk/Subject.cc | 2 +- src/MenuCreator.cc | 2 +- src/Remember.cc | 2 +- src/Toolbar.cc | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba96feb..d1818f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ (Format: Year/Month/Day) Changes for 1.0.0: +*07/09/07: + * Fix crash when changing toolbar visibility, #1786765 (Mark) + FbTk/MenuItem.cc *07/08/27: * Fix hardcoded Mod1, use ModKey() now (Mathias) Window.cc diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index ee17204..b0fcb4b 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -506,7 +506,7 @@ void Menu::updateMenu(int active_index) { void Menu::show() { - if (isVisible() || !menuitems.size()) + if (isVisible() || menuitems.empty()) return; m_visible = true; diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc index 82dd155..bc80ca0 100644 --- a/src/FbTk/MenuItem.cc +++ b/src/FbTk/MenuItem.cc @@ -34,8 +34,11 @@ namespace FbTk { void MenuItem::click(int button, int time) { - if (m_command.get() != 0) - m_command->execute(); + if (m_command.get() != 0) { + // we need a local variable, since the command may destroy this object + RefCount tmp(m_command); + tmp->execute(); + } } void MenuItem::drawLine(FbDrawable &draw, const MenuTheme &theme, size_t size, diff --git a/src/FbTk/Subject.cc b/src/FbTk/Subject.cc index 2b30fd8..08a211c 100644 --- a/src/FbTk/Subject.cc +++ b/src/FbTk/Subject.cc @@ -64,7 +64,7 @@ void Subject::notify() { m_notify_mode = false; // remove dead observers - if (m_dead_observers.size()) { + if (!m_dead_observers.empty()) { std::for_each(m_dead_observers.begin(), m_dead_observers.end(), std::bind1st(std::mem_fun(&Subject::detach), this)); diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 8507388..fefb3dc 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -325,7 +325,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve if (submenu == 0) return; - if (str_cmd.size()) + if (!str_cmd.empty()) submenu->setLabel(str_cmd); else submenu->setLabel(str_label); diff --git a/src/Remember.cc b/src/Remember.cc index 2de6d86..f5a5ac8 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -387,7 +387,7 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { bool had_error = false; - if (!str_key.size()) + if (str_key.empty()) continue; //read next line if (strcasecmp(str_key.c_str(), "Workspace") == 0) { unsigned int w; diff --git a/src/Toolbar.cc b/src/Toolbar.cc index ad1a8e5..b5ad967 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -412,7 +412,7 @@ void Toolbar::reconfigure() { m_tools = tools; // copy values - if (m_tools.size()) { + if (!m_tools.empty()) { // make lower case transform(m_tools.begin(), m_tools.end(), m_tools.begin(), -- cgit v0.11.2