]> git.sur5r.net Git - i3/i3/commitdiff
Crash when we get the percentages wrong.
authorFernando Tarlá Cardoso Lemos <fernandotcl@gmail.com>
Tue, 25 Jan 2011 23:47:37 +0000 (21:47 -0200)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 27 Jan 2011 12:00:14 +0000 (13:00 +0100)
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

index b79d463fa9f9967ed430db0bcf9cdb82b16dac70..c6ebb5ccb0c4f97dd39731a9f6c6d4faab7925b8 100644 (file)
@@ -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;
             }