From 4a4db10ea843882793d72484c15dec2860678d44 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 10 Apr 2011 20:17:04 -0300 Subject: [PATCH] Add some checks in move_focus() for null pointers in gui/manager.cpp. --- src/gui/manager.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/gui/manager.cpp b/src/gui/manager.cpp index eaa27928d..6a8a2ca0c 100644 --- a/src/gui/manager.cpp +++ b/src/gui/manager.cpp @@ -1453,21 +1453,24 @@ static bool move_focus(JWidget manager, Message* msg) Widget* focus = NULL; Widget* it; bool ret = false; - Frame* window; + Frame* window = NULL; int c, count; - /* who have the focus */ - if (focus_widget) - window = static_cast(focus_widget->getRoot()); - else if (!jlist_empty(manager->children)) + // Who have the focus + if (focus_widget) { + window = dynamic_cast(focus_widget->getRoot()); + } + else if (!jlist_empty(manager->children)) { window = TOPWND(manager); - else - return ret; + } - /* how many child-widget want the focus in this widget? */ + if (!window) + return false; + + // How many child-widget want the focus in this widget? count = count_widgets_accept_focus(window); - /* one at least */ + // One at least if (count > 0) { std::vector list(count); @@ -1553,6 +1556,8 @@ static bool move_focus(JWidget manager, Message* msg) static int count_widgets_accept_focus(JWidget widget) { + ASSERT(widget != NULL); + int count = 0; JLink link;