From 268fe91434eba882db59ff6962731d7c3d1fa031 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 --- widget.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/widget.c b/widget.c index 33d99953..1a52ba33 100644 --- a/widget.c +++ b/widget.c @@ -304,8 +304,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);