From 89917976c7689b6466bc8cfce05d981d26d98183 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fernando=20Tarl=C3=A1=20Cardoso=20Lemos?= Date: Tue, 25 Jan 2011 21:47:37 -0200 Subject: [PATCH] Crash when we get the percentages wrong. Better to crash with an assertion than to get into an infinite loop. We cold work around this, but there's a bug here and it's not a rounding bug, so it's better not to conceal it. --- src/render.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/render.c b/src/render.c index b79d463f..c6ebb5cc 100644 --- a/src/render.c +++ b/src/render.c @@ -118,9 +118,12 @@ void render_con(Con *con, bool render_fullscreen) { double percentage = child->percent > 0.0 ? child->percent : 1.0 / children; assigned += sizes[i++] = percentage * total; } + assert(assigned == total || + (assigned > total && assigned - total <= children * 2) || + (assigned < total && total - assigned <= children * 2)); int signal = assigned < total ? 1 : -1; while (assigned != total) { - for (i = 0; i < children && assigned < total; ++i) { + for (i = 0; i < children && assigned != total; ++i) { sizes[i] += signal; assigned += signal; } -- 2.39.5