From db0014540691a11f98d7794ff4c22acc31e06d70 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 23 Mar 2014 17:48:26 +0100 Subject: [PATCH] wibox.layout.base.fit_widget: Enforce sane width and height Previously, odd things could happen if a widget was getting fitted into a negative width or, even worse, width being NaN (not a number)! This can e.g. happen due to a margin layout which doesn't get enough space to even draw the margin that it is supposed to add. Fix this by enforcing a minimum value of 0 for the width and height that a widget gets fitted into. Signed-off-by: Uli Schlachter --- lib/wibox/layout/base.lua.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/wibox/layout/base.lua.in b/lib/wibox/layout/base.lua.in index f0f99646..d5f9f982 100644 --- a/lib/wibox/layout/base.lua.in +++ b/lib/wibox/layout/base.lua.in @@ -32,6 +32,12 @@ end -- @param height The available height for the widget -- @return The width and height that the widget wants to use function base.fit_widget(widget, width, height) + -- Sanitize the input. This also filters out e.g. NaN. + local width = math.max(0, width) + local height = math.max(0, height) + + -- Since the geometry cache is a weak table, we have to be careful when + -- doing lookups. We can't do "if cache[width] ~= nil then"! local cache = widget._fit_geometry_cache local result = cache[width] if not result then