From c368b848176d3201f4763101de0de544fa7be7b5 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 17 Sep 2010 16:08:06 +0200 Subject: [PATCH] widget layouts: Check the number of geometries If we called the widget layout for x widgets, but the layouts returned less geometries than this, we silently ignored the left-over widgets. If the layouts returned more geometries, we crashed. Fix this by verifying that the number of widgets and the number of geometries are equal. If they are different, we use the smaller of the two. Signed-off-by: Uli Schlachter --- objects/widget.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/objects/widget.c b/objects/widget.c index f043f47d..01b86708 100644 --- a/objects/widget.c +++ b/objects/widget.c @@ -305,8 +305,18 @@ widget_render(wibox_t *wibox) /* remove wibox */ lua_remove(globalconf.L, -1); + size_t num_widgets = lua_objlen(L, -1); + if(lua_objlen(L, -1) != (size_t) widgets->len) + { + warn("Widget layout returned wrong number of geometries. Got %d widgets and %lu geometries.", + widgets->len, (unsigned long) lua_objlen(L, -1)); + /* Set num_widgets to min(widgets->len, lua_objlen(L, -1)); */ + if(num_widgets > (size_t) widgets->len) + num_widgets = widgets->len; + } + /* get computed geometries */ - for(unsigned int i = 0; i < lua_objlen(L, -1); i++) + for(size_t i = 0; i < num_widgets; i++) { lua_pushnumber(L, i + 1); lua_gettable(L, -2);