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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-17 16:08:06 +02:00
parent 8c0a83f5ca
commit 268fe91434
1 changed files with 11 additions and 1 deletions

View File

@ -304,8 +304,18 @@ widget_render(wibox_t *wibox)
/* remove wibox */ /* remove wibox */
lua_remove(globalconf.L, -1); 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 */ /* 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_pushnumber(L, i + 1);
lua_gettable(L, -2); lua_gettable(L, -2);