From 5b2e9c01392c106a8841eba8f5f901eb07dc93f2 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 9 Mar 2008 16:12:18 +0100 Subject: [PATCH] [awesome-menu] Fix infinite loop on bad completion --- awesome-menu.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/awesome-menu.c b/awesome-menu.c index c8b15c1d2..29bd70bfc 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -268,6 +268,7 @@ item_list_fill_file(const char *directory) static void complete(Bool reverse) { + int loop = 2; item_t *item = NULL; item_t *(*item_iter)(item_t **, item_t *) = item_list_next_cycle; @@ -277,14 +278,10 @@ complete(Bool reverse) if(globalconf.item_selected) item = item_iter(&globalconf.items, globalconf.item_selected); else - for(item = globalconf.items; item; item = item_iter(&globalconf.items, item)) - if(item->match) - { - globalconf.item_selected = item; - break; - } + item = globalconf.items; - for(; item; item = item_iter(&globalconf.items, item)) + for(; item && loop; item = item_iter(&globalconf.items, item)) + { if(item->match) { /* XXX sizeof wrong */ @@ -292,6 +289,15 @@ complete(Bool reverse) globalconf.item_selected = item; return; } + /* + * Since loop is 2, it will be 1 at first iter, and then 0 if we + * get back before matching an item (i.e. no items match) to the + * first elem: so it will break the loop, otherwise it loops for + * ever + */ + if(item == globalconf.items) + loop--; + } } static void